Example #1
0
 def update_tags(self, tags):
     """Update the requests tags"""
     tag_set = set()
     for tag in parse_tags(tags):
         new_tag, _ = Tag.objects.get_or_create(name=tag)
         tag_set.add(new_tag)
     self.tags.set(*tag_set)
Example #2
0
    def post(self, request, **kwargs):
        """Edit the question or answer"""
        # pylint: disable=unused-argument

        question = self.get_object()
        obj_type = request.POST.get('object')

        if obj_type == 'question':
            self._question(request, question)
        elif obj_type == 'answer':
            try:
                self._answer(request)
            except Answer.DoesNotExist:
                pass

        tags = request.POST.get('tags')
        if tags:
            tag_set = set()
            for tag in parse_tags(tags):
                new_tag, _ = Tag.objects.get_or_create(name=tag)
                tag_set.add(new_tag)
            self.get_object().tags.set(*tag_set)
            self.get_object().save()
            messages.success(request,
                             'Your tags have been saved to this question.')

        return redirect(question)
Example #3
0
 def post(self, request, **kwargs):
     """Handles POST requests on article pages"""
     # pylint:disable=unused-argument
     article = self.get_object()
     authorized = self.request.user.is_staff
     action = request.POST.get('action')
     clear_cache = False
     if not authorized:
         return HttpResponseForbidden()
     if action == 'projects':
         form = ProjectManagerForm(request.POST, user=request.user)
         if form.is_valid():
             projects = form.cleaned_data['projects']
             article.projects = projects
             clear_cache = True
     tags = request.POST.get('tags')
     if tags:
         tag_set = set()
         for tag in parse_tags(tags):
             new_tag, _ = Tag.objects.get_or_create(name=tag)
             tag_set.add(new_tag)
         article.tags.set(*tag_set)
         clear_cache = True
     if clear_cache:
         article.clear_cache()
     return redirect(article)
Example #4
0
 def _set_tags(self, instance, tags):
     """Set tags"""
     if tags is not None:
         tag_set = set()
         for tag in parse_tags(",".join(tags)):
             new_tag, _ = Tag.objects.get_or_create(name=tag)
             tag_set.add(new_tag)
         instance.tags.set(*tag_set)
Example #5
0
 def _tags(self, foias, user, post):
     """Add tags to the selected requests"""
     foias = [f for f in foias if f.has_perm(user, 'change')]
     tags = [
         Tag.objects.get_or_create(name=t)
         for t in parse_tags(post.get('tags', ''))
     ]
     tags = [t for t, _ in tags]
     for foia in foias:
         foia.tags.add(*tags)
     return 'Tags added to requests'