from datetime import datetime, timedelta

from ckan.logic.auth.delete import package_delete, resource_delete

ERROR_STRING = """Nu este permisa stergerea datelor la mai mult de 5 zile dupa
    data incarcarii, deoarece aceste date au intrat in circuitul public."""


def romania_theme_package_delete(context, data_dict):
    model = context['model']
    package = model.Session.query(model.Package).get(data_dict['id'])
    if datetime.now() - package.metadata_created > timedelta(days=5):
        return {'success': False, 'msg': ERROR_STRING}
    return package_delete(context, data_dict)


def romania_theme_resource_delete(context, data_dict):
    model = context['model']
    resource = model.Session.query(model.Resource).get(data_dict['id'])
    if datetime.now() - resource.created > timedelta(days=5):
        return {'success': False, 'msg': ERROR_STRING}
    return resource_delete(context, data_dict)

@@ -357,36 +357,16 @@
 ckage = 
-model.Session.query(
 model.Pa
@@ -370,17 +370,16 @@
 .Package
-)
 .get(dat
@@ -384,32 +384,33 @@
 ata_dict%5B'id'%5D)%0A
+%0A
     if datetime.
@@ -669,28 +669,8 @@
 e = 
-model.Session.query(
 mode
@@ -679,17 +679,16 @@
 Resource
-)
 .get(dat
@@ -701,16 +701,17 @@
 %5B'id'%5D)%0A
+%0A
     if d

Fix deleting resources