Пример #1
0
    def post(self, request, *args, **kwargs):
        topic_id = self.kwargs.get('topic_id')
        like = self.request.POST.get('like')

        ilike = False
        if like == 'true':
            ilike = True
        
        try:
            topic = Topic.objects.get(id=topic_id)
            if ilike:
                topic.liker.remove(request.user)
                ilike = False
            else:
                topic.liker.add(request.user)
                ilike = True
                
                if not topic.like_reward and topic.liker.count() >= 10:
                    user_reward(topic.author, settings.REP_TOPIC_LIKE, topic_id=topic.id)
                    topic.like_reward = True
                    topic.author.profile.save()
            
        except Topic.DoesNotExist:
            json_data = JsonReturn.error(JsonReturn.J_ERROR,str(_("the topic dose not exist")))
        except:
            json_data = JsonReturn.error(JsonReturn.J_ERROR, str(_("unknown error")))
        else:
            json_data = JsonReturn.success("ok")
            json_data.set_value('topicid', topic_id)
            json_data.set_value('ilike', ilike)
#             json_data.set_value('count', topic.liker.count())
        
        return self.ajax_response(json_data)
Пример #2
0
    def _commit_changes(self, topic, reply, mentioned_user):
        topic.reply_count += 1
        if not topic.reply_reward and topic.reply_count >= 10:
            user_reward(topic.author,
                        settings.REP_TOPIC_REPLY,
                        topic_id=topic.id)
            topic.reply_reward = True
            topic.author.profile.save()

        if mentioned_user:
            for u in mentioned_user:
                data = {}
                data['replier'] = reply.author
                data['topic'] = topic

                detail = render_to_string(
                    "forum/notification/reply_notification.html", data)
                n = Notification(user=u, detail=detail.strip())
                u.profile.has_notification = True
                u.profile.save()
                n.save()

        topic.last_replied = timezone.now()

        reply.save()
        topic.save()
Пример #3
0
    def post(self, request, *args, **kwargs):
        topic_id = self.kwargs.get('topic_id')
        like = self.request.POST.get('like')

        ilike = False
        if like == 'true':
            ilike = True

        try:
            topic = Topic.objects.get(id=topic_id)
            if ilike:
                topic.liker.remove(request.user)
                ilike = False
            else:
                topic.liker.add(request.user)
                ilike = True

                if not topic.like_reward and topic.liker.count() >= 10:
                    user_reward(topic.author,
                                settings.REP_TOPIC_LIKE,
                                topic_id=topic.id)
                    topic.like_reward = True
                    topic.author.profile.save()

        except Topic.DoesNotExist:
            json_data = JsonReturn.error(JsonReturn.J_ERROR,
                                         str(_("the topic dose not exist")))
        except:
            json_data = JsonReturn.error(JsonReturn.J_ERROR,
                                         str(_("unknown error")))
        else:
            json_data = JsonReturn.success("ok")
            json_data.set_value('topicid', topic_id)
            json_data.set_value('ilike', ilike)


#             json_data.set_value('count', topic.liker.count())

        return self.ajax_response(json_data)
Пример #4
0
    def post(self, request, *args, **kwargs):
        data = self.get_context_data()
        form = data["form"]
        if form.is_valid():
            profile = request.user.profile

            avatar = form.cleaned_data['avatar']
            display_name = form.cleaned_data['display_name']
            description = form.cleaned_data['description']
            website = form.cleaned_data['website']
            company = form.cleaned_data['company']
            email = form.cleaned_data['email']
            location = form.cleaned_data['location']
            github = form.cleaned_data['github']
            gitlab = form.cleaned_data['gitlab']

            if avatar:
                self._save_avatar(profile, avatar)

            if not profile.profile_init_reward:
                if avatar and display_name:
                    user_reward(request.user, settings.REP_USER_INIT)
                    profile.profile_init_reward = True

            profile.display_name = display_name
            profile.description = description
            profile.website = website
            profile.company = company
            profile.email = email
            profile.location = location
            profile.github = github
            profile.gitlab = gitlab

            profile.save()

            return HttpResponseRedirect(reverse('settings_profile'))

        return super(TemplateView, self).render_to_response(data)
Пример #5
0
 def post(self, request, *args, **kwargs):
     data = self.get_context_data()
     form = data["form"]
     if form.is_valid():
         profile = request.user.profile
         
         avatar = form.cleaned_data['avatar']
         display_name = form.cleaned_data['display_name']
         description = form.cleaned_data['description']
         website = form.cleaned_data['website']
         company = form.cleaned_data['company']
         email = form.cleaned_data['email']
         location = form.cleaned_data['location']
         github = form.cleaned_data['github']
         gitlab = form.cleaned_data['gitlab']
         
         if avatar:
             self._save_avatar(profile, avatar)
         
         if not profile.profile_init_reward:
             if avatar and display_name:
                 user_reward(request.user, settings.REP_USER_INIT)
                 profile.profile_init_reward = True
         
         profile.display_name = display_name
         profile.description = description
         profile.website = website
         profile.company = company
         profile.email = email
         profile.location = location
         profile.github = github
         profile.gitlab = gitlab
         
         profile.save()
         
         return HttpResponseRedirect(reverse('settings_profile'))
     
     return super(TemplateView, self).render_to_response(data)
Пример #6
0
 def _commit_changes(self, topic, reply, mentioned_user):
     topic.reply_count += 1
     if not topic.reply_reward and topic.reply_count >= 10:
         user_reward(topic.author, settings.REP_TOPIC_REPLY, topic_id=topic.id)
         topic.reply_reward = True
         topic.author.profile.save()
     
     if mentioned_user:
         for u in mentioned_user:
             data = {}
             data['replier'] = reply.author
             data['topic'] = topic
             
             detail = render_to_string("forum/notification/reply_notification.html", data)
             n = Notification(user=u, detail=detail.strip())
             u.profile.has_notification = True
             u.profile.save()
             n.save()
     
     topic.last_replied = timezone.now()
     
     reply.save()
     topic.save()