예제 #1
0
파일: models.py 프로젝트: Emergya/peer
    def metarefresh(self):

        noid_msg = "Error: Entity %s doesn't have entityid" % (self.id)

        if not hasattr(self, 'entityid'):
            return noid_msg

        url = self.entityid
        if not url:
            return noid_msg

        try:
            text = fetch_resource(url)
            if text is None:
                text = fetch_resource('http://' + url)

                if text is None:
                    return 'Unknown error while fetching the url'
        except FetchError as e:
            return str(e)

        if not text:
            return 'Empty metadata not allowed'

        content = write_temp_file(text)
        name = self.metadata.name
        commit_msg = 'Updated automatically from %s' % (url)
        self.metadata.save(name, content, self.owner.username, commit_msg)

        self.metarefresh_last_run = datetime.now()
        self.save()

        return 'Success: Data was updated successfully'
예제 #2
0
    def metarefresh(self):

        noid_msg = "Error: Entity %s doesn't have entityid" % (self.id)

        if not hasattr(self, 'entityid'):
            return noid_msg

        url = self.entityid
        if not url:
            return noid_msg

        try:
            text = fetch_resource(url)
            if text is None:
                text = fetch_resource('http://' + url)

                if text is None:
                    return 'Unknown error while fetching the url'
        except FetchError as e:
            return str(e)

        if not text:
            return 'Empty metadata not allowed'

        content = write_temp_file(text)
        name = self.metadata.name
        commit_msg = 'Updated automatically from %s' % (url)
        self.metadata.save(name, content, self.owner.username, commit_msg)

        self.metarefresh_last_run = datetime.now()
        self.save()

        return 'Success: Data was updated successfully'
예제 #3
0
파일: forms.py 프로젝트: enriquepablo/peer
    def save(self):
        content = write_temp_file(self.metadata)

        name = self.entity.metadata.name
        username = authorname(self.user)
        commit_msg = self.cleaned_data['commit_msg_' + self.type].encode('utf8')
        self.entity.metadata.save(name, content, username, commit_msg)
        self.entity.save()
예제 #4
0
 def save(self, *args, **kwargs):
     super(BaseEntityCategoryForm, self).save(*args, **kwargs)
     entity = self.instance.entity
     md_str = etree.tostring(entity._load_metadata().etree,
             pretty_print=True)
     if settings.MODERATION_ENABLED:
         entity.try_to_complete(md_str)
     else:
         content = write_temp_file(md_str)
         name = entity.metadata.name
         username = authorname(self.user)
         commit_msg = 'Saving SP categories'
         entity.metadata.save(name, content, username, commit_msg)
     entity.save()
예제 #5
0
파일: forms.py 프로젝트: rhoerbe/peer
 def save(self, action):
     content = write_temp_file(self.metadata)
     name = self.entity.metadata.name
     username = authorname(self.user)
     commit_msg = self.cleaned_data['commit_msg_' + self.type].encode('utf8')
     if settings.MODERATION_ENABLED:
         if action == 'submit_changes':
             self.entity.modify(self.metadata)
         elif action == 'approve_changes':
             self.entity.approve(name, content, username, commit_msg)
         elif action == 'discard_changes':
             self.entity.reject()
     else:
         self.entity.metadata.save(name, content, username, commit_msg)
     self.entity.save()
예제 #6
0
    def save(self, action):
        content = write_temp_file(self.metadata)
        name = self.entity.metadata.name
        username = authorname(self.user)
        commit_msg = self.cleaned_data['commit_msg_' + self.type].encode('utf8')
        if settings.MODERATION_ENABLED:
            if action == 'update_changes':
                self.entity.try_to_complete(self.metadata)
            elif action == 'submit_changes':
                self.entity.try_to_submit(self.metadata)
            elif action == 'approve_changes':
                self.entity.try_to_approve(self.metadata, name, content,
                        username, commit_msg)
            elif action == 'discard_changes':
                self.entity.try_to_reject()
        else:
            self.entity.metadata.save(name, content, username, commit_msg)
        self.entity.save()
        self.entity.store_mdui_database()
        self.entity.store_contacts_database()
        self.store_entitymd_database(self.entity.id)
        if self.entity.role_descriptor == 'SP':
            self.entity.store_spcategory_database()
        elif self.entity.role_descriptor == 'IDP':
            self.entity.store_idpcategory_database()

        mail_owner = True if self.entity.owner != self.user else False
        if mail_owner:
            if not settings.MODERATION_ENABLED:
                action = 'modified'
            else:
                if action == 'update_changes':
                    action = 'saved changes for'
                if action == 'submit_changes':
                    action = 'submitted changes for'
                if action == 'approve_changes':
                    action = 'approved changes for'
                if action == 'discard_changes':
                    action = 'discarded changes for'
            msg = ('Dear {owner},\n{moderator} has {action} the entity '
                    'with EntityID {entityid}.'.format(
                        owner=unicode(self.entity.owner),
                        moderator=unicode(self.user),
                        action=action.replace('_', ' '),
                        entityid=self.entity.entityid))
            send_mail('Entity modified', msg, settings.DEFAULT_FROM_EMAIL,
                    [self.entity.owner.email])
예제 #7
0
def manage_mdui_data(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)

    MDUIdataFormSet = modelformset_factory(MDUIdata,
                                           form=MDUIdataForm,
                                           max_num=len(settings.MDUI_LANGS),
                                           validate_max=True,
                                           min_num=len(settings.MDUI_LANGS),
                                           validate_min=True)

    if request.method == 'POST':
        formset = MDUIdataFormSet(
            request.POST, queryset=MDUIdata.objects.filter(entity=entity))
        if formset.is_valid():
            for form in formset:
                form.save()
            md_str = etree.tostring(entity._load_metadata().etree,
                                    pretty_print=True)
            if settings.MODERATION_ENABLED:
                entity.try_to_complete(md_str)
            else:
                content = write_temp_file(md_str)
                name = entity.metadata.name
                username = authorname(request.user)
                commit_msg = 'Saving MDUI Data'
                entity.metadata.save(name, content, username, commit_msg)
            entity.save()
            msg = _('MDUI data successfully changed')
            messages.success(request, msg)
            return HttpResponseRedirect(
                reverse('entities:entity_view', args=(entity_id, )))
    else:
        if entity.mdui.count():
            queryset = MDUIdata.objects.filter(entity=entity)
            formset = MDUIdataFormSet(queryset=queryset)
        else:
            queryset = MDUIdata.objects.none()
            initial = [{
                'entity': entity,
                'lang': lang[0]
            } for lang in settings.MDUI_LANGS]
            formset = MDUIdataFormSet(initial=initial, queryset=queryset)
    context = {'formset': formset, 'entity': entity}
    return render(request, 'entity/manage_mdui_data.html', context)
예제 #8
0
파일: mdui.py 프로젝트: Emergya/peer
def manage_mdui_data(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)

    MDUIdataFormSet = modelformset_factory(MDUIdata,
            form=MDUIdataForm,
            max_num=len(settings.MDUI_LANGS), validate_max=True,
            min_num=len(settings.MDUI_LANGS), validate_min=True)

    if request.method == 'POST':
        formset = MDUIdataFormSet(request.POST,
                queryset=MDUIdata.objects.filter(entity=entity))
        if formset.is_valid():
            for form in formset:
                form.save()
            md_str = etree.tostring(entity._load_metadata().etree,
                    pretty_print=True)
            if settings.MODERATION_ENABLED:
                entity.try_to_complete(md_str)
            else:
                content = write_temp_file(md_str)
                name = entity.metadata.name
                username = authorname(request.user)
                commit_msg = 'Saving MDUI Data'
                entity.metadata.save(name, content, username, commit_msg)
            entity.save()
            msg = _('MDUI data successfully changed')
            messages.success(request, msg)
            return HttpResponseRedirect(reverse('entities:entity_view',
                                         args=(entity_id,)))
    else:
        if entity.mdui.count():
            queryset = MDUIdata.objects.filter(entity=entity)
            formset = MDUIdataFormSet(queryset=queryset)
        else:
            queryset = MDUIdata.objects.none()
            initial = [{'entity': entity, 'lang': lang[0]}
                                       for lang in settings.MDUI_LANGS]
            formset = MDUIdataFormSet(initial=initial, queryset=queryset)
    context = {
            'formset': formset,
            'entity': entity
            }
    return render(request, 'entity/manage_mdui_data.html', context)