コード例 #1
0
def create_dss_how_to_texts(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    Content = apps.get_model("cms", "Content")

    with disable_permission_checks(Content):
        # first check if an entry exists
        dss_container_list_how_to = Content.objects.using(db_alias).filter(
            slug="dss_container_list_how_to"
        ).first()
        # if no entry exists, we create an "empty" one
        if not dss_container_list_how_to:
            Content.objects.using(db_alias).create(
                slug="dss_container_list_how_to",
                title="DSS Container List How To",
                text=LIST_TEXT+GENERAL_TEXT,
            )
        # first check if an entry exists
        dss_container_detail_how_to = Content.objects.using(db_alias).filter(
            slug="dss_container_detail_how_to"
        ).first()
        # if no entry exists, we create an "empty" one
        if not dss_container_detail_how_to:
            Content.objects.using(db_alias).create(
                slug="dss_container_detail_how_to",
                title="DSS Container Detail How To",
                text=DETAIL_TEXT + GENERAL_TEXT,
            )

    RevisionModelMixin.set_enabled(True)
コード例 #2
0
def reverse_refactor_bookingrules(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    ResourceBookingRuleBookableHours = apps.get_model("projects", "ResourceBookingRuleBookableHours")
    Resource = apps.get_model("projects", "Resource")

    for resource_item in Resource.objects.using(db_alias).all():
        old_bookingrule = ResourceBookingRuleBookableHours(
            resource=resource_item
        )
        for bookingrule in ResourceBookingRuleBookableHours.objects.using(db_alias).filter(resource=resource_item):
            old_bookingrule.time_start = bookingrule.time_start
            old_bookingrule.time_end = bookingrule.time_end
            old_bookingrule.full_day = bookingrule.full_day
            if bookingrule.weekday == "MON":
                old_bookingrule.monday = True
            if bookingrule.weekday == "TUE":
                old_bookingrule.tuesday = True
            if bookingrule.weekday == "WED":
                old_bookingrule.wednesday = True
            if bookingrule.weekday == "THU":
                old_bookingrule.thursday = True
            if bookingrule.weekday == "FRI":
                old_bookingrule.friday = True
            if bookingrule.weekday == "SAT":
                old_bookingrule.saturday = True
            if bookingrule.weekday == "SUN":
                old_bookingrule.sunday = True
            bookingrule.delete()
        if old_bookingrule.time_start:
            old_bookingrule.save()
コード例 #3
0
def convert_from_truefalse_to_allowdenyneutral(apps, schema_editor):
    """
    Converts ModelPrivilege
    if can_view/can_edit/can_delete/can_restore is True, then we set the new "choices" can_view/... to "AL" (allow)
    :param apps:
    :param schema_editor:
    :return:
    """
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    ModelPrivilege = apps.get_model('model_privileges', 'ModelPrivilege')

    with disable_permission_checks(ModelPrivilege):
        # iterate over all model privileges and fill the new allow/deny/neutral privileges
        for model_privilege in ModelPrivilege.objects.using(db_alias).all():
            if model_privilege.is_owner:
                model_privilege.full_access_privilege = PRIVILEGE_CHOICES_ALLOW
            if model_privilege.can_view:
                model_privilege.view_privilege = PRIVILEGE_CHOICES_ALLOW
            if model_privilege.can_edit:
                model_privilege.edit_privilege = PRIVILEGE_CHOICES_ALLOW
            if model_privilege.can_delete:
                model_privilege.delete_privilege = PRIVILEGE_CHOICES_ALLOW
            if model_privilege.can_restore:
                model_privilege.restore_privilege = PRIVILEGE_CHOICES_ALLOW

            model_privilege.save()

    RevisionModelMixin.set_enabled(True)
def refactor_general_usage_setting(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    Resource = apps.get_model("projects", "Resource")
    with disable_permission_checks(Resource):
        for item in Resource.objects.using(db_alias).all():
            if item.general_usage_setting == 'NST':
                item.general_usage_setting = None
                item.save()
    RevisionModelMixin.set_enabled(True)
コード例 #5
0
def reverse_func(apps, schema_editor):
    """
    Iterate over all tasks, meetings, notes, contacts, files and takes the first projects element from each element and
     sets it on the foreign key relationship
    :param apps:
    :param schema_editor:
    :return:
    """
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    Task = apps.get_model('projects', 'Task')
    Note = apps.get_model('projects', 'Note')
    Meeting = apps.get_model('projects', 'Meeting')
    Contact = apps.get_model('projects', 'Contact')
    File = apps.get_model('projects', 'File')

    with disable_permission_checks(Task):
        # iterate over all tasks
        for task in Task.objects.using(db_alias).all():
            if task.projects.all().count() > 0:
                task.project = task.projects.all().first()
                task.save()

    with disable_permission_checks(Meeting):
        # iterate over all meetings
        for meeting in Meeting.objects.using(db_alias).all():
            if meeting.projects.all().count() > 0:
                meeting.project = meeting.projects.all().first()
                meeting.save()

    with disable_permission_checks(Note):
        # iterate over all notes
        for note in Note.objects.using(db_alias).all():
            if note.projects.all().count() > 0:
                note.project = note.projects.all().first()
                note.save()

    with disable_permission_checks(Contact):
        # iterate over all contacts
        for contact in Contact.objects.using(db_alias).all():
            if contact.projects.all().count() > 0:
                contact.project = contact.projects.all().first()
                contact.save()

    with disable_permission_checks(File):
        # iterate over all files
        for file in File.objects.using(db_alias).all():
            if file.projects.all().count() > 0:
                file.project = file.projects.all().first()
                file.save()

    RevisionModelMixin.set_enabled(True)
コード例 #6
0
def refactor_general_usage_settings(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    Resource = apps.get_model("projects", "Resource")
    with disable_permission_checks(Resource):
        for item in Resource.objects.using(db_alias).all():
            if item.general_usage_setting != 'GLB':
                if item.usage_setting_selected_user_groups.exists():
                    item.general_usage_setting = 'GRP'
                else:
                    item.general_usage_setting = 'NST'
                item.save()
    RevisionModelMixin.set_enabled(True)
コード例 #7
0
def forwards_func(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    User = apps.get_model('auth', 'User')
    Task = apps.get_model('projects', 'Task')
    TaskAssignedUser = apps.get_model('projects', 'TaskAssignedUser')

    # iterate over all tasks
    for task in Task.objects.using(db_alias).all():
        TaskAssignedUser.objects.using(db_alias).create(
            task=task, assigned_user=task.assigned_user)

    RevisionModelMixin.set_enabled(True)
コード例 #8
0
def set_meeting_resource_null(apps, schema_editor):
    """
    Sets all resources in meetings to null to avoid problems with booking rule validation
    :param apps:
    :param schema_editor:
    :return:
    """
    RevisionModelMixin.set_enabled(False)

    Meeting = apps.get_model('shared_elements', 'Meeting')

    with disable_permission_checks(Meeting):
        Meeting.objects.update(resource=None)

    RevisionModelMixin.set_enabled(True)
コード例 #9
0
def forwards_func(apps, schema_editor):
    """
    Iterates over all tasks, meetings, notes, contacts, files and converts the ForeignKey relationship to project
    into a many to many relationship for projects
    :param apps:
    :param schema_editor:
    :return:
    """
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    Task = apps.get_model('projects', 'Task')
    Note = apps.get_model('projects', 'Note')
    Meeting = apps.get_model('projects', 'Meeting')
    Contact = apps.get_model('projects', 'Contact')
    File = apps.get_model('projects', 'File')

    with disable_permission_checks(Task):
        # iterate over all tasks
        for task in Task.objects.using(db_alias).all():
            if task.project:
                task.projects.add(task.project)

    with disable_permission_checks(Meeting):
        # iterate over all meetings
        for meeting in Meeting.objects.using(db_alias).all():
            if meeting.project:
                meeting.projects.add(meeting.project)

    with disable_permission_checks(Note):
        # iterate over all notes
        for note in Note.objects.using(db_alias).all():
            if note.project:
                note.projects.add(note.project)

    with disable_permission_checks(Contact):
        # iterate over all contacts
        for contact in Contact.objects.using(db_alias).all():
            if contact.project:
                contact.projects.add(contact.project)

    with disable_permission_checks(File):
        # iterate over all files
        for file in File.objects.using(db_alias).all():
            if file.project:
                file.projects.add(file.project)

    RevisionModelMixin.set_enabled(True)
コード例 #10
0
def set_full_day_according_to_times_for_tasks(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    Task = apps.get_model("shared_elements", "Task")

    with disable_permission_checks(Task):
        # first get all entries that are full days
        all_full_day_entries = Task.objects.using(db_alias).filter(
            start_date__hour=0,
            start_date__minute=0,
            due_date__hour=23,
            due_date__minute=59,
        )
        # then update them
        all_full_day_entries.update(full_day=True)

    RevisionModelMixin.set_enabled(True)
コード例 #11
0
def set_full_day_according_to_times(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    ResourceBookingRuleBookableHours = apps.get_model(
        "projects", "ResourceBookingRuleBookableHours")

    with disable_permission_checks(ResourceBookingRuleBookableHours):
        zero_time = time(0, 0, 0)
        # first get all entries that are not full days
        all_non_full_day_entries = ResourceBookingRuleBookableHours.objects.using(
            db_alias).exclude(
                time_start=zero_time,
                time_end=zero_time,
            )
        all_non_full_day_entries.update(full_day=False)

    RevisionModelMixin.set_enabled(True)
コード例 #12
0
def create_maintenance_text(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    Content = apps.get_model("cms", "Content")

    with disable_permission_checks(Content):
        # first check if an entry exists
        maintenance_text = Content.objects.using(db_alias).filter(
            slug="maintenance"
        ).first()

        # if no entry exists, we create an "empty" one
        if not maintenance_text:
            Content.objects.using(db_alias).create(
                slug="maintenance",
                title="Maintenance"
            )
    RevisionModelMixin.set_enabled(True)
コード例 #13
0
def forwards_func(apps, schema_editor):
    """
    Iterates over all dmps and converts the ForeignKey relationship to project
    into a many to many relationship for projects
    :param apps:
    :param schema_editor:
    :return:
    """
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    Dmp = apps.get_model('dmp', 'Dmp')

    with disable_permission_checks(Dmp):
        # iterate over all tasks
        for dmp in Dmp.objects.using(db_alias).all():
            if dmp.project:
                dmp.projects.add(dmp.project)

    RevisionModelMixin.set_enabled(True)
コード例 #14
0
def reverse_func(apps, schema_editor):
    """
    Iterate over all dmps and take the first projects element from each element and set it on the foreign key relationship
    :param apps:
    :param schema_editor:
    :return:
    """
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    Dmp = apps.get_model('dmp', 'Dmp')

    with disable_permission_checks(Dmp):
        # iterate over all dmps
        for dmp in Dmp.objects.using(db_alias).all():
            if dmp.projects.all().count() > 0:
                dmp.project = dmp.projects.all().first()
                dmp.save()

    RevisionModelMixin.set_enabled(True)
コード例 #15
0
def refactor_bookingrules(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    ResourceBookingRuleBookableHours = apps.get_model("projects", "ResourceBookingRuleBookableHours")
    for item in ResourceBookingRuleBookableHours.objects.using(db_alias).all():
        if item.tuesday:
            create_bookingrule(ResourceBookingRuleBookableHours, item, "TUE", db_alias)
        if item.wednesday:
            create_bookingrule(ResourceBookingRuleBookableHours, item, "WED", db_alias)
        if item.thursday:
            create_bookingrule(ResourceBookingRuleBookableHours, item, "THU", db_alias)
        if item.friday:
            create_bookingrule(ResourceBookingRuleBookableHours, item, "FRI", db_alias)
        if item.saturday:
            create_bookingrule(ResourceBookingRuleBookableHours, item, "SAT", db_alias)
        if item.sunday:
            create_bookingrule(ResourceBookingRuleBookableHours, item, "SUN", db_alias)
        if not item.monday:
            item.delete()
    RevisionModelMixin.set_enabled(True)
コード例 #16
0
def convert_from_allowdenyneutral_to_truefalse(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    ModelPrivilege = apps.get_model('model_privileges', 'ModelPrivilege')

    with disable_permission_checks(ModelPrivilege):
        # iterate over all model privileges and fill the new allow/deny/neutral privileges
        for model_privilege in ModelPrivilege.objects.using(db_alias).all():
            if model_privilege.view_privilege == PRIVILEGE_CHOICES_ALLOW:
                model_privilege.can_view = True
            if model_privilege.edit_privilege == PRIVILEGE_CHOICES_ALLOW:
                model_privilege.can_edit = True
            if model_privilege.delete_privilege == PRIVILEGE_CHOICES_ALLOW:
                model_privilege.can_delete = True
            if model_privilege.restore_privilege == PRIVILEGE_CHOICES_ALLOW:
                model_privilege.can_restore = True

            model_privilege.save()

    RevisionModelMixin.set_enabled(True)
コード例 #17
0
def create_footer_pages(apps, schema_editor):
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias
    Content = apps.get_model("cms", "Content")

    with disable_permission_checks(Content):
        # first check if an entry exists
        imprint_page = Content.objects.using(db_alias).filter(
            slug="imprint").first()
        # if no entry exists, we create an "empty" one
        if not imprint_page:
            Content.objects.using(db_alias).create(slug="imprint",
                                                   title="Imprint")

        # first check if an entry exists
        privacy_page = Content.objects.using(db_alias).filter(
            slug="privacy").first()
        # if no entry exists, we create an "empty" one
        if not privacy_page:
            Content.objects.using(db_alias).create(slug="privacy",
                                                   title="Privacy")

        # first check if an entry exists
        accessibility_page = Content.objects.using(db_alias).filter(
            slug="accessibility").first()
        # if no entry exists, we create an "empty" one
        if not accessibility_page:
            Content.objects.using(db_alias).create(slug="accessibility",
                                                   title="Accessibility")

        # first check if an entry exists
        frontend_licenses_page = Content.objects.using(db_alias).filter(
            slug="frontend_licenses").first()
        # if no entry exists, we create an "empty" one
        if not frontend_licenses_page:
            Content.objects.using(db_alias).create(slug="frontend_licenses",
                                                   title="Frontend Licenses")
    RevisionModelMixin.set_enabled(True)
コード例 #18
0
def forwards_func(apps, schema_editor):
    """
    Iterates over all files and sets the new title field to the value of the current name field
    :param apps:
    :param schema_editor:
    :return:
    """
    RevisionModelMixin.set_enabled(False)
    db_alias = schema_editor.connection.alias

    File = apps.get_model('shared_elements', 'File')

    with disable_permission_checks(File):
        with disable_permission_checks(Version):
            # iterate over all files
            for file in File.objects.using(db_alias).all():
                # set the title to the content of name
                file.title = file.name
                # set the name to the original_filename
                file.name = file.original_filename
                file.save()
                # get all versions for this file

    RevisionModelMixin.set_enabled(True)
コード例 #19
0
ファイル: middlewares.py プロジェクト: eWorkbench/eWorkbench
 def process_response(self, request, response):
     if request.method in ["GET", "HEAD", "OPTIONS"]:
         # enable the revision model / changesets again
         RevisionModelMixin.set_enabled(True)
     return response
コード例 #20
0
ファイル: middlewares.py プロジェクト: eWorkbench/eWorkbench
 def process_request(self, request):
     if request.method in ["GET", "HEAD", "OPTIONS"]:
         # disable the revision model / changesets
         RevisionModelMixin.set_enabled(False)