Ejemplo n.º 1
0
def switch_links_order(request, link_pk_1, link_pk_2):
    if request.is_ajax():
        # check rights to moderate
        is_modo = is_moderator(request.user)
        if is_modo is False:
            return HttpResponse('')
        # get the objects
        try:
            links = Link.objects.filter(
                pk__in=[link_pk_1, link_pk_2]).select_related(
                    'category').order_by('order')
        except Link.ObjectDoesNotExist:
            return HttpResponse('')
        link1 = links.filter(pk=link_pk_1)[0]
        link2 = links.filter(pk=link_pk_2)[0]
        category = link1.category
        link1_order = link1.order
        link2_order = link2.order
        print str(link1.order) + ' / ' + str(link2.order)
        # switdh order
        link1.order = link2_order
        link2.order = link1_order
        link1.save()
        link2.save()
        return HttpResponseRedirect(
            reverse('links-category-list', kwargs={'slug': category.slug}) +
            '?edit_mode=1')
    else:
        raise Http404
Ejemplo n.º 2
0
def switch_links_order(request, link_pk_1, link_pk_2):
    if request.is_ajax():
        # check rights to moderate
        is_modo = is_moderator(request.user)
        if is_modo is False:
            return HttpResponse('')
        # get the objects
        try:
            links = Link.objects.filter(pk__in=[link_pk_1,link_pk_2]).select_related('category').order_by('order')
        except Link.ObjectDoesNotExist:
            return HttpResponse('')
        link1 = links.filter(pk=link_pk_1)[0]
        link2 = links.filter(pk=link_pk_2)[0]
        category = link1.category
        link1_order = link1.order
        link2_order = link2.order
        print str(link1.order)+' / '+str(link2.order)
        # switdh order
        link1.order = link2_order
        link2.order = link1_order
        link1.save()
        link2.save()
        return HttpResponseRedirect(reverse('links-category-list', kwargs={'slug': category.slug})+'?edit_mode=1')
    else:
        raise Http404
Ejemplo n.º 3
0
 def get_context_data(self, **kwargs):
     context = super(LinksHomeView, self).get_context_data(**kwargs)
     categories = Category.objects.filter(level__lte=0, status=0)
     num_links = Link.objects.all().count()
     is_modo = is_moderator(self.request.user)
     if is_modo:
         num_items_in_queue = Link.objects.filter(status=1).count()
         context['num_items_in_queue'] = num_items_in_queue
     context['is_moderator'] = is_modo
     context['categories'] = categories
     context['num_links'] = num_links
     return context
Ejemplo n.º 4
0
def moderate_confirm_action(request, id, action):
    if request.is_ajax():
        # check rights to mmoderate
        is_modo = is_moderator(request.user)
        if is_modo is False:
            return HttpResponse('')
        return render(request, 'linkcat/moderation/moderate_link_confirm.html',
                                    {'id':id, 'action':action},
                                    content_type="application/xhtml+xml"
                                    )
    else:
        raise Http404
Ejemplo n.º 5
0
 def get_context_data(self, **kwargs):
     context = super(LinksHomeView, self).get_context_data(**kwargs)
     categories = Category.objects.filter(level__lte=0, status=0)
     num_links = Link.objects.all().count()
     is_modo = is_moderator(self.request.user)
     if is_modo:
         num_items_in_queue = Link.objects.filter(status=1).count()
         context['num_items_in_queue'] = num_items_in_queue
     context['is_moderator'] = is_modo
     context['categories'] = categories
     context['num_links'] = num_links 
     return context
Ejemplo n.º 6
0
def moderate_confirm_action(request, id, action):
    if request.is_ajax():
        # check rights to mmoderate
        is_modo = is_moderator(request.user)
        if is_modo is False:
            return HttpResponse('')
        return render(request,
                      'linkcat/moderation/moderate_link_confirm.html', {
                          'id': id,
                          'action': action
                      },
                      content_type="application/xhtml+xml")
    else:
        raise Http404
Ejemplo n.º 7
0
 def get_context_data(self, **kwargs):
     context = super(LinksAndCategoriesView, self).get_context_data(**kwargs)
     edit_mode = False
     last_level = self.category.level+1
     categories = self.category.get_descendants().filter(level__lte=last_level, status=0)
     ancestors = self.category.get_ancestors()
     parent = None
     if len(ancestors) > 0:
         parent = ancestors.reverse()[0]
     edit_mode = False
     context['categories'] = categories.order_by('order')
     if self.request.GET.has_key('edit_mode'):
         context['edit_mode'] = True
     context['is_moderator'] = is_moderator(self.request.user)
     context['num_links'] = len(self.links)
     context['category'] = self.category
     context['ancestors'] = ancestors
     context['parent'] = parent
     context['links'] = self.links
     context['default_language'] = DEFAULT_LANGUAGE
     return context
Ejemplo n.º 8
0
def moderate_link(request, id, action):
    if request.is_ajax():
        # check rights to moderate
        is_modo = is_moderator(request.user)
        if is_modo is False:
            return HttpResponse('')
        # get the link
        try:
            link = Link.objects.get(pk=int(id))
        except:
            return HttpResponse('Error: link not found')
        # process action
        if action == 'accept':
            link.status = 0
            link.save()
        elif action == 'reject':
            link.delete()
        return render(request,
                      'linkcat/moderation/link_moderated.html', {'id': id},
                      content_type="application/xhtml+xml")
    else:
        raise Http404
Ejemplo n.º 9
0
 def get_context_data(self, **kwargs):
     context = super(LinksAndCategoriesView,
                     self).get_context_data(**kwargs)
     edit_mode = False
     last_level = self.category.level + 1
     categories = self.category.get_descendants().filter(
         level__lte=last_level, status=0)
     ancestors = self.category.get_ancestors()
     parent = None
     if len(ancestors) > 0:
         parent = ancestors.reverse()[0]
     edit_mode = False
     context['categories'] = categories.order_by('order')
     if self.request.GET.has_key('edit_mode'):
         context['edit_mode'] = True
     context['is_moderator'] = is_moderator(self.request.user)
     context['num_links'] = len(self.links)
     context['category'] = self.category
     context['ancestors'] = ancestors
     context['parent'] = parent
     context['links'] = self.links
     context['default_language'] = DEFAULT_LANGUAGE
     return context
Ejemplo n.º 10
0
def moderate_link(request, id, action):
    if request.is_ajax():
        # check rights to moderate
        is_modo = is_moderator(request.user)
        if is_modo is False:
            return HttpResponse('')
        # get the link
        try:
            link = Link.objects.get(pk=int(id))
        except:
            return HttpResponse('Error: link not found')
        # process action
        if action == 'accept':
            link.status = 0
            link.save()
        elif action == 'reject':
            link.delete()
        return render(request, 'linkcat/moderation/link_moderated.html',
                                  {'id':id},
                                    content_type="application/xhtml+xml"
                                    )
    else:
        raise Http404