Пример #1
0
def FollowView(request, pk, slug):
    jaryanak = get_object_or_404(Jaryanak, pk=pk)
    # followed = Follow.objects.get_for_user(user=request.user, jaryanak=jaryanak)
    if request.user in jaryanak.followers.all():
        followed = True
    else:
        followed = False
    # if request.method == 'Text':
    if 'next' in request.GET:
        next = request.GET['next']
    elif hasattr(jaryanak, 'get_absolute_url'):
        if callable(getattr(jaryanak, 'get_absolute_url')):
            next = jaryanak.get_absolute_url()
        else:
            next = jaryanak.get_absolute_url
    else:
        raise AttributeError('Define get_absolute_url')

    if followed:
        f = Follow.objects.get_for_user(user=request.user, jaryanak=jaryanak)
        f.delete()
    else:
        f = Follow(user=request.user, jaryanak=jaryanak)
        f.save()

    return HttpResponseRedirect(next)
Пример #2
0
def FollowView(request, pk, slug):
    jaryanak = get_object_or_404(Jaryanak, pk=pk)
    # followed = Follow.objects.get_for_user(user=request.user, jaryanak=jaryanak)
    if request.user in jaryanak.followers.all():
        followed = True
    else:
        followed = False
    # if request.method == 'Text':
    if 'next' in request.GET:
        next = request.GET['next']
    elif hasattr(jaryanak, 'get_absolute_url'):
        if callable(getattr(jaryanak, 'get_absolute_url')):
            next = jaryanak.get_absolute_url()
        else:
            next = jaryanak.get_absolute_url
    else:
        raise AttributeError('Define get_absolute_url')

    if followed:
        f = Follow.objects.get_for_user(user=request.user, jaryanak=jaryanak)
        f.delete()
    else:
        f = Follow(user=request.user, jaryanak=jaryanak)
        f.save()

    return HttpResponseRedirect(next)
Пример #3
0
 def form_valid(self, form):
     f = form.save(commit=False)
     f.admin = self.request.user
     f.save()
     follow = Follow(user=self.request.user, jaryanak=f)
     follow.save()
     # jaryanak = Jaryanak.objects.get(pk=f.pk)
     # user = self.request.user 
     # mem = Membership(user=user, jaryanak=jaryanak)
     # mem.save()
     return super(JaryanakCreateView, self).form_valid(form)
Пример #4
0
 def form_valid(self, form):
     f = form.save(commit=False)
     f.admin = self.request.user
     f.save()
     follow = Follow(user=self.request.user, jaryanak=f)
     follow.save()
     # jaryanak = Jaryanak.objects.get(pk=f.pk)
     # user = self.request.user
     # mem = Membership(user=user, jaryanak=jaryanak)
     # mem.save()
     return super(JaryanakCreateView, self).form_valid(form)
Пример #5
0
def InviteAcceptView(request, key, decision):
	invite = get_object_or_404(Invite, key=key)

	if invite.is_usable():
		if decision == "accept":
			invitee = request.user
			jaryanak = invite.jaryanak
			invite.mark_accepted()
			m = Membership(user=invitee, jaryanak=jaryanak)
			m.save()
			f = Follow(user=invitee, jaryanak=jaryanak)
			f.save()
			return HttpResponseRedirect(reverse('profile', kwargs={'slug': request.user}))
		elif decision == "reject":
			invite.mark_used()
			messages.error(request, "You just rejected the invite.")
			return redirect("home")
		elif decision == "expire":
			invite.mark_expired()
			messages.success(request, "You just cancelled your invitation")
			return redirect("home")
	else:
		return redirect("home")
Пример #6
0
def InviteAcceptView(request, key, decision):
    invite = get_object_or_404(Invite, key=key)

    if invite.is_usable():
        if decision == "accept":
            invitee = request.user
            jaryanak = invite.jaryanak
            invite.mark_accepted()
            m = Membership(user=invitee, jaryanak=jaryanak)
            m.save()
            f = Follow(user=invitee, jaryanak=jaryanak)
            f.save()
            return HttpResponseRedirect(
                reverse('profile', kwargs={'slug': request.user}))
        elif decision == "reject":
            invite.mark_used()
            messages.error(request, "You just rejected the invite.")
            return redirect("home")
        elif decision == "expire":
            invite.mark_expired()
            messages.success(request, "You just cancelled your invitation")
            return redirect("home")
    else:
        return redirect("home")