示例#1
0
    def obj_update(self, bundle, request=None, **kwargs):
        try:
            action = bundle.request.user.action_set.all()[0]
        except:
            action = Action()
            action.user_id = bundle.request.user.id

        action.like_cost = bundle.data.get('like', 1) 
        action.share_cost = bundle.data.get('share', 1)
        action.comment_cost = bundle.data.get('comment', 1)
        action.save()

        return bundle
示例#2
0
    def dehydrate(self, bundle):
        try:
            action = bundle.request.user.action_set.all()[0]
        except:
            action = Action()
            action.like_cost = 1
            action.share_cost = 1
            action.comment_cost = 1
            action.user_id = bundle.request.user.id
            action.save()

        bundle.data.clear()
        bundle.data['like_cost'] = action.like_cost
        bundle.data['share_cost'] = action.share_cost
        bundle.data['comment_cost'] = action.comment_cost

        return bundle;
示例#3
0
    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            return redirect("/")

        first_name = request.POST.get("first_name", "")
        last_name = request.POST.get("first_name", "")
        email = request.POST.get("email", "")
        password = request.POST.get("password", "")

        try:
            user = User.objects.get(email=email)
        except:
            try:
                user = User.objects.get(username=email)
            except:
                user = None

        if user is not None:
            return render_to_response(
                "register.html", {"error": "Email already registered"}, context_instance=RequestContext(request)
            )

        user = User.objects.create_user(username=email, email=email, password=password)
        user.first_name = first_name
        user.last_name = last_name
        user.is_active = True
        user.save()

        action = Action()
        action.like_cost = 1
        action.share_cost = 1
        action.comment_cost = 1
        action.user_id = user.id
        action.save()

        # Login the user now
        user = authenticate(username=email, password=password)
        login(request, user)
        return redirect("/")