예제 #1
0
 def check_remove(self, request):
     """
     Marks a feature as removed a month after it's been implemented
     """
     if self.implemented_on and not self.notifications_sent:
         
         # Send notifications that this feature's been implemented
         # First to the original requesting user
         send_email(request, {
             'feature': self,
         }, 'feature_vote/implemented.eml', to_email=(self.user_email,))
         self.notifications_sent = True
         self.save()
         
         # And now, using the developer messages framework, to all voting
         # users
         voting_sessions = set()
         for session in Session.objects.all():
             if 'feature_vote:votes' in session.get_decoded():
                 if self.id in session.get_decoded()['feature_vote:votes']:
                     voting_sessions.add(session.session_key)
         
         for session_key in voting_sessions:
             UserMessage.objects.create(session_key=session_key,
                                        message="A feature you voted on (%s), has now been implemented!" % self.title)
         
     if not self.is_removed and self.implemented_on and \
       self.implemented_on + self.REMOVE_AFTER_IMPLEMENTED_FOR < datetime.now():
         self.is_removed = True
         self.save()
예제 #2
0
    def handle_POST(self, request, context):
        form = context['form']
        post = request.POST.copy()

        if 'vote_up.x' in post:
            post['vote_up'] = post['vote_up.x']

        if 'vote_down.x' in post:
            post['vote_down'] = post['vote_down.x']

        if 'vote_up' in post or 'vote_down' in post:
            feature = get_object_or_404(Feature, id=post.get('id', 0))
            previous_vote = request.session['feature_vote:votes'].get(
                feature.id, 0)
            vote = previous_vote + (1 if 'vote_up' in post else -1)
            vote = min(max(-1, vote), 1)
            request.session['feature_vote:votes'][feature.id] = vote
            request.session.modified = True

            feature.down_vote += self.vote_transitions[(previous_vote,
                                                        vote)][0]
            feature.up_vote += self.vote_transitions[(previous_vote, vote)][1]

            feature.save()

            if request.POST.get('return_url', '').startswith('/'):
                return self.redirect(request.POST['return_url'], request,
                                     'seeother')
            else:
                return self.redirect(reverse('feature_vote:index'), request,
                                     'seeother')

        if form.is_valid():
            form.save()

            send_email(
                request, {
                    'name': form.cleaned_data['user_name'],
                    'email': form.cleaned_data['user_email'],
                    'title': form.cleaned_data['title'],
                    'description': form.cleaned_data['description'],
                    'feature': form.instance,
                }, 'feature_vote/feature_create.eml', self)

            return self.redirect(
                reverse('feature_vote:index') + '?submitted=true', request,
                'seeother')
        else:
            return self.handle_GET(request, context)
예제 #3
0
    def handle_POST(self, request, context):
        form = context['form']
        post = request.POST.copy()

        if 'vote_up.x' in post:
            post['vote_up'] = post['vote_up.x']

        if 'vote_down.x' in post:
            post['vote_down'] = post['vote_down.x']

        if 'vote_up' in post or 'vote_down' in post:
            feature = get_object_or_404(Feature, id=post.get('id', 0))
            previous_vote = request.session['feature_vote:votes'].get(feature.id, 0)
            vote = previous_vote + (1 if 'vote_up' in post else -1)
            vote = min(max(-1, vote), 1)
            request.session['feature_vote:votes'][feature.id] = vote
            request.session.modified = True

            feature.down_vote += self.vote_transitions[(previous_vote, vote)][0]
            feature.up_vote += self.vote_transitions[(previous_vote, vote)][1]

            feature.save()

            if request.POST.get('return_url', '').startswith('/'):
                return self.redirect(request.POST['return_url'], request,
                                     'seeother')
            else:
                return self.redirect(reverse('feature_vote:index'), request,
                                     'seeother')

        if form.is_valid():
            form.save()

            send_email(request, {
                'name': form.cleaned_data['user_name'],
                'email': form.cleaned_data['user_email'],
                'title': form.cleaned_data['title'],
                'description': form.cleaned_data['description'],
                'feature': form.instance,
            }, 'feature_vote/feature_create.eml', self)

            return self.redirect(reverse('feature_vote:index') + '?submitted=true',
                                 request, 'seeother')
        else:
            return self.handle_GET(request, context)
예제 #4
0
    def handle_POST(cls, request, context):
        form = context["form"]

        if request.POST.get("csrf") != request.session["feature_vote:csrf"]:
            return HttpResponseForbidden()

        if "vote_up" in request.POST or "vote_down" in request.POST:
            feature = get_object_or_404(Feature, id=request.POST.get("id", 0))
            previous_vote = request.session["feature_vote:votes"].get(feature.id, 0)
            vote = previous_vote + (1 if "vote_up" in request.POST else -1)
            vote = min(max(-1, vote), 1)
            request.session["feature_vote:votes"][feature.id] = vote
            request.session.modified = True

            feature.down_vote += cls.vote_transitions[(previous_vote, vote)][0]
            feature.up_vote += cls.vote_transitions[(previous_vote, vote)][1]

            feature.save()

            if request.POST.get("return_url", "").startswith("/"):
                return HttpResponseSeeOther(request.POST["return_url"])
            else:
                return HttpResponseSeeOther(reverse("feature_vote:index"))

        if form.is_valid():
            form.save()

            send_email(
                request,
                {
                    "name": form.cleaned_data["user_name"],
                    "email": form.cleaned_data["user_email"],
                    "title": form.cleaned_data["title"],
                    "description": form.cleaned_data["description"],
                    "feature": form.instance,
                },
                "feature_vote/feature_create.eml",
                cls,
            )

            return HttpResponseSeeOther(reverse("feature_vote:index") + "?submitted=true")
        else:
            return cls.handle_GET(request, context)
예제 #5
0
    def handle_POST(self, request, context):
        form = context['form']

        if request.POST.get('csrf') != request.session['feature_vote:csrf']:
            return HttpResponseForbidden()

        if 'vote_up' in request.POST or 'vote_down' in request.POST:
            feature = get_object_or_404(Feature, id=request.POST.get('id', 0))
            previous_vote = request.session['feature_vote:votes'].get(
                feature.id, 0)
            vote = previous_vote + (1 if 'vote_up' in request.POST else -1)
            vote = min(max(-1, vote), 1)
            request.session['feature_vote:votes'][feature.id] = vote
            request.session.modified = True

            feature.down_vote += self.vote_transitions[(previous_vote,
                                                        vote)][0]
            feature.up_vote += self.vote_transitions[(previous_vote, vote)][1]

            feature.save()

            if request.POST.get('return_url', '').startswith('/'):
                return HttpResponseSeeOther(request.POST['return_url'])
            else:
                return HttpResponseSeeOther(reverse('feature_vote:index'))

        if form.is_valid():
            form.save()

            send_email(
                request, {
                    'name': form.cleaned_data['user_name'],
                    'email': form.cleaned_data['user_email'],
                    'title': form.cleaned_data['title'],
                    'description': form.cleaned_data['description'],
                    'feature': form.instance,
                }, 'feature_vote/feature_create.eml', self)

            return HttpResponseSeeOther(
                reverse('feature_vote:index') + '?submitted=true')
        else:
            return self.handle_GET(request, context)
예제 #6
0
    def handle_POST(self, request, context):
        form = context['form']

        if request.POST.get('csrf') != request.session['feature_vote:csrf']:
            return HttpResponseForbidden()

        if 'vote_up' in request.POST or 'vote_down' in request.POST:
            feature = get_object_or_404(Feature, id = request.POST.get('id', 0))
            previous_vote = request.session['feature_vote:votes'].get(feature.id, 0)
            vote = previous_vote + (1 if 'vote_up' in request.POST else -1)
            vote = min(max(-1, vote), 1)
            request.session['feature_vote:votes'][feature.id] = vote
            request.session.modified = True

            feature.down_vote += self.vote_transitions[(previous_vote, vote)][0]
            feature.up_vote += self.vote_transitions[(previous_vote, vote)][1]

            feature.save()

            if request.POST.get('return_url', '').startswith('/'):
                return HttpResponseSeeOther(request.POST['return_url'])
            else:
                return HttpResponseSeeOther(reverse('feature_vote:index'))

        if form.is_valid():
            form.save()

            send_email(request, {
                'name': form.cleaned_data['user_name'],
                'email': form.cleaned_data['user_email'],
                'title': form.cleaned_data['title'],
                'description': form.cleaned_data['description'],
                'feature': form.instance,
            }, 'feature_vote/feature_create.eml', self)

            return HttpResponseSeeOther(reverse('feature_vote:index') + '?submitted=true')
        else:
            return self.handle_GET(request, context)
예제 #7
0
    def handle_POST(cls, request, context):
        form = context['feedback_form']
        if form.is_valid():
            # Send an e-mail to the managers notifying of feedback.
            email = send_email(request, {
                'email': form.cleaned_data['email'],
                'referer': request.POST.get('referer', ''),
                'body': form.cleaned_data['body'],
            }, 'feedback/email.txt', cls)

            qs = urllib.urlencode({
                'sent': 'true',
                'referer': request.POST.get('referer', ''),
            })

            return HttpResponseRedirect('%s?%s' %
                                        (reverse('feedback:index'), qs))

        else:
            return cls.handle_GET(request, context)
예제 #8
0
    def handle_POST(self, request, context):
        form = context['feedback_form']
        if form.is_valid():
            # Send an e-mail to the managers notifying of feedback.
            email = send_email(request, {
                'email': form.cleaned_data['email'],
                'referer': request.POST.get('referer', ''),
                'body': form.cleaned_data['body'],
            }, 'feedback/email.txt', self)

            qs = urllib.urlencode({
                'sent': 'true',
                'referer': request.POST.get('referer', ''),
            })

            return HttpResponseRedirect('%s?%s' %
                                        (reverse('feedback:index'), qs))

        else:
            return self.handle_GET(request, context)