コード例 #1
0
ファイル: goal.py プロジェクト: arkhi/bookwyrm
    def post(self, request, username, year):
        """update or create an annual goal"""
        user = get_user_from_username(request.user, username)
        if user != request.user:
            return HttpResponseNotFound()

        year = int(year)
        goal = models.AnnualGoal.objects.filter(year=year, user=request.user).first()
        form = forms.GoalForm(request.POST, instance=goal)
        if not form.is_valid():
            data = {
                "goal_form": form,
                "goal": goal,
                "year": year,
            }
            return TemplateResponse(request, "goal.html", data)
        goal = form.save()

        if request.POST.get("post-status"):
            # create status, if appropraite
            template = get_template("snippets/generated_status/goal.html")
            create_generated_note(
                request.user,
                template.render({"goal": goal, "user": request.user}).strip(),
                privacy=goal.privacy,
            )

        return redirect(request.headers.get("Referer", "/"))
コード例 #2
0
ファイル: goal.py プロジェクト: tastytea/bookwyrm
    def post(self, request, username, year):
        ''' update or create an annual goal '''
        user = get_user_from_username(request.user, username)
        if user != request.user:
            return HttpResponseNotFound()

        year = int(year)
        goal = models.AnnualGoal.objects.filter(year=year,
                                                user=request.user).first()
        form = forms.GoalForm(request.POST, instance=goal)
        if not form.is_valid():
            data = {
                'title':
                '%s\'s %d Reading' % (request.user.display_name, year),
                'goal_form': form,
                'goal': goal,
                'year': year,
            }
            return TemplateResponse(request, 'goal.html', data)
        goal = form.save()

        if request.POST.get('post-status'):
            # create status, if appropraite
            template = get_template('snippets/generated_status/goal.html')
            create_generated_note(request.user,
                                  template.render({
                                      'goal': goal,
                                      'user': request.user
                                  }).strip(),
                                  privacy=goal.privacy)

        return redirect(request.headers.get('Referer', '/'))
コード例 #3
0
ファイル: helpers.py プロジェクト: HonusDaniel/bookwyrm
def handle_reading_status(user, shelf, book, privacy):
    """ post about a user reading a book """
    # tell the world about this cool thing that happened
    try:
        message = {
            "to-read": "wants to read",
            "reading": "started reading",
            "read": "finished reading",
        }[shelf.identifier]
    except KeyError:
        # it's a non-standard shelf, don't worry about it
        return

    status = create_generated_note(user, message, mention_books=[book], privacy=privacy)
    status.save()
コード例 #4
0
ファイル: outgoing.py プロジェクト: SHSauler/bookwyrm
def handle_reading_status(user, shelf, book, privacy):
    ''' post about a user reading a book '''
    # tell the world about this cool thing that happened
    try:
        message = {
            'to-read': 'wants to read',
            'reading': 'started reading',
            'read': 'finished reading'
        }[shelf.identifier]
    except KeyError:
        # it's a non-standard shelf, don't worry about it
        return

    status = create_generated_note(user,
                                   message,
                                   mention_books=[book],
                                   privacy=privacy)
    status.save()

    broadcast(user, status.to_create_activity(user))