Exemplo n.º 1
0
def action(request, aid, rid, state):
    announcement = get_object_or_404(models.Announcement, id=aid)
    registration = get_object_or_404(models.Registration, id=rid)

    if not request.user == announcement.author or registration.status:
        return redirect(reverse('carshare:show', kwargs={'aid': aid}))

    if state == 'accepted' and announcement.available_places() > 0:
        notify(
            "Votre demande de covoiturage a été acceptée",
            "carshare:show", {'aid': announcement.id},
            [registration.user],
        )
        registration.status = 'accepted'
    elif state == 'refused':
        notify(
            "Votre demande de covoiturage a été refusée",
            "carshare:show", {'aid': announcement.id},
            [registration.user],
        )
        registration.status = 'refused'
    else:
        return redirect(reverse('carshare:show', kwargs={'aid': aid}))

    registration.save()
    return redirect(reverse('carshare:show', kwargs={'aid': aid}))
Exemplo n.º 2
0
def action(request, aid, rid, state):
    announcement = get_object_or_404(models.Announcement, id=aid)
    registration = get_object_or_404(models.Registration, id=rid)

    if not request.user == announcement.author or registration.status:
        return redirect(reverse('carshare:show', kwargs={'aid': aid}))

    if state == 'accepted' and announcement.available_places() > 0:
        notify(
            "Votre demande de covoiturage a été acceptée",
            "carshare:show",
            {'aid': announcement.id},
            [registration.user],
        )
        registration.status = 'accepted'
    elif state == 'refused':
        notify(
            "Votre demande de covoiturage a été refusée",
            "carshare:show",
            {'aid': announcement.id},
            [registration.user],
        )
        registration.status = 'refused'
    else:
        return redirect(reverse('carshare:show', kwargs={'aid': aid}))

    registration.save()
    return redirect(reverse('carshare:show', kwargs={'aid': aid}))
Exemplo n.º 3
0
def delete(request, aid):
    announcement = get_object_or_404(models.Announcement, id=aid)
    if request.user == announcement.author or request.user.has_perm(
            'carshare.change_announcement'):
        registrations = models.Registration.objects.filter(
            announcement=announcement).all()
        users = set(reg.user for reg in registrations
                    if reg.user != request.user)
        notify("L'offre de covoiturage a été supprimée", "carshare:index", {},
               users)
        announcement.delete()
    return redirect(reverse('carshare:index'))
Exemplo n.º 4
0
def add_prof(request):
    prof_form = ProfForm(request.POST or None)
    if prof_form.is_valid():
        prof_form = prof_form.save(commit=False)
        prof_form.save()
        notify("Un nouveau prof a été proposé",
               'quotes:manage_prof', {},
               perms=['manage_prof'])
        prof_form = ProfForm()
    context = {'prof_form': prof_form}

    return render(request, 'quotes/add_prof.html', context)
Exemplo n.º 5
0
def delete(request, aid):
    announcement = get_object_or_404(models.Announcement, id=aid)
    if request.user == announcement.author or request.user.has_perm('carshare.change_announcement'):
        registrations = models.Registration.objects.filter(announcement=announcement).all()
        users = set(reg.user for reg in registrations if reg.user != request.user)
        notify(
            "L'offre de covoiturage a été supprimée",
            "carshare:index", {},
            users
        )
        announcement.delete()
    return redirect(reverse('carshare:index'))
Exemplo n.º 6
0
def show(request, aid):
    announcement = get_object_or_404(
        models.Announcement.objects.select_related('author__profile'), id=aid)

    context = {
        'announcement':
        announcement,
        'registrations':
        models.Registration.objects.filter(
            announcement=announcement).all().select_related('user__profile'),
        'user_is_author':
        request.user == announcement.author,
    }

    if request.method == "POST":
        form = forms.RegistrationForm(request.POST)
        if form.is_valid():
            registration = form.save(commit=False)
            registration.announcement = announcement
            registration.user = request.user
            if request.POST[
                    'action'] == 'register' and request.user != announcement.author:
                registration.is_simple_comment = False
                notify(
                    "%s a publié une demande de covoiturage." %
                    str(request.user.profile),
                    "carshare:show",
                    {'aid': aid},
                    [announcement.author],
                )
            else:
                registrations = models.Registration.objects.filter(
                    announcement=announcement).all()
                users = set(reg.user for reg in registrations
                            if reg.user != request.user)
                notify(
                    "%s a commenté une offre de covoiturage à laquelle vous avez participé"
                    % str(request.user.profile),
                    "carshare:show",
                    {'aid': aid},
                    users,
                )
            registration.save()
            form.save()
            return redirect(
                reverse('carshare:show', kwargs={'aid': announcement.id}))
        else:
            context['form'] = form
    else:
        context['form'] = forms.RegistrationForm()

    return render(request, 'carshare/show.html', context)
Exemplo n.º 7
0
def add_quote(request):
    quote_form = QuoteForm(request.POST or None)
    quote_form.fields['prof'].queryset = Prof.objects.filter(approved=True)
    if quote_form.is_valid():
        quote = quote_form.save(commit=False)
        quote.author = request.user
        quote.save()
        notify("Une nouvelle citation a été proposée",
               'quotes:manage_quotes', {},
               perms=['manage_quote'])
        quote_form = QuoteForm()
    context = {'quote_form': quote_form}

    return render(request, 'quotes/add_quote.html', context)
Exemplo n.º 8
0
    def buy(self, user, payment_mean, seller):
        buy = BuyingHistory(user=user,
                            pack=self,
                            type='pack',
                            payment_mean=payment_mean,
                            seller=seller)
        buy.save()
        notify("Confirmation de l'achat de «%s»" % self.name,
               "shop:index", {},
               users=[user])

        for product in self.products.filter(enabled=True).all():
            fnc = ACTIONS_FNC_MAPPING[product.action]
            fnc(user, product, payment_mean)
            if product.event:
                product.create_event_registration(user)
Exemplo n.º 9
0
def account_request(request):
    if request.user.is_authenticated():
        return redirect(reverse('news:index'))

    if request.method == 'POST':
        form = forms.UserRequestForm(request.POST)
        if form.is_valid():
            form.save()
            notify('Une demande de création de compte à été déposée.',
                   'accounts:list_request',
                   groups=Group.objects.filter(name=settings.BDE_GROUP_NAME))
            return redirect(reverse('accounts:confirmation'))
    else:
        form = forms.UserRequestForm()

    context = {'form': form}
    return render(request, 'accounts/request.html', context)
Exemplo n.º 10
0
    def buy(self, user, payment_mean, seller):
        buy = BuyingHistory(
            user=user,
            product=self,
            type='product',
            payment_mean=payment_mean,
            seller=seller,
        )
        buy.save()
        notify("Confirmation de l'achat de «%s»" % self.name,
               "shop:index", {},
               users=[user])
        fnc = ACTIONS_FNC_MAPPING[self.action]
        fnc(user, self, payment_mean)

        if self.event:
            self.create_event_registration(user)
Exemplo n.º 11
0
def comment(request, nid):
    n = get_object_or_404(models.News, id=nid)
    coms = models.Comment.objects.filter(news=n).select_related('user__profile')
    context = {"news": n, "comments": coms}

    if request.method == "POST":
        form = forms.CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.news = n
            comment.user = request.user
            comment.save()
            notify(
                "Un commentaire a été posté sur une news",
                "news:comment", {'nid': n.id},
                [n.author]
            )
    else:
        form = forms.CommentForm()
    context['comment_form'] = form
    return render(request, "news/comment.html", context)
Exemplo n.º 12
0
def account_request(request):
    if request.user.is_authenticated():
        return redirect(reverse('news:index'))

    if request.method == 'POST':
        form = forms.UserRequestForm(request.POST)
        if form.is_valid():
            form.save()
            notify(
                'Une demande de création de compte à été déposée.',
                'accounts:list_request',
                groups=Group.objects.filter(name=settings.BDE_GROUP_NAME)
            )
            return redirect(reverse('accounts:confirmation'))
    else:
        form = forms.UserRequestForm()

    context = {
        'form': form
    }
    return render(request, 'accounts/request.html', context)
Exemplo n.º 13
0
def show(request, aid):
    announcement = get_object_or_404(models.Announcement.objects.select_related('author__profile'), id=aid)

    context = {
        'announcement': announcement,
        'registrations': models.Registration.objects.filter(announcement=announcement).all().select_related('user__profile'),
        'user_is_author': request.user == announcement.author,
    }

    if request.method == "POST":
        form = forms.RegistrationForm(request.POST)
        if form.is_valid():
            registration = form.save(commit=False)
            registration.announcement = announcement
            registration.user = request.user
            if request.POST['action'] == 'register' and request.user != announcement.author:
                registration.is_simple_comment = False
                notify(
                    "%s a publié une demande de covoiturage." % str(request.user.profile),
                    "carshare:show", {'aid': aid},
                    [announcement.author],
                )
            else:
                registrations = models.Registration.objects.filter(announcement=announcement).all()
                users = set(reg.user for reg in registrations if reg.user != request.user)
                notify(
                    "%s a commenté une offre de covoiturage à laquelle vous avez participé" % str(request.user.profile),
                    "carshare:show", {'aid': aid},
                    users,
                )
            registration.save()
            form.save()
            return redirect(reverse('carshare:show', kwargs={'aid': announcement.id}))
        else:
            context['form'] = form
    else:
        context['form'] = forms.RegistrationForm()

    return render(request, 'carshare/show.html', context)
Exemplo n.º 14
0
def edit(request, aid):
    announcement = get_object_or_404(models.Announcement, id=aid)
    context = {'announcement': announcement}

    if request.user != announcement.author and not request.user.has_perm(
            'carshare.change_announcement'):
        return redirect('news:index')

    if request.method == "POST":
        form = forms.AnnouncementForm(request.POST, instance=announcement)
        if form.is_valid():
            form.save()
            registrations = models.Registration.objects.filter(
                announcement=announcement).all()
            users = set(reg.user for reg in registrations
                        if reg.user != request.user)
            notify("L'offre de covoiturage a été éditée", "carshare:show",
                   {"aid": announcement.id}, users)
            return redirect(reverse('carshare:show', kwargs={'aid': aid}))
        else:
            context['form'] = form
    else:
        context['form'] = forms.AnnouncementForm(instance=announcement)
    return render(request, 'carshare/edit.html', context)
Exemplo n.º 15
0
def edit(request, aid):
    announcement = get_object_or_404(models.Announcement, id=aid)
    context = {'announcement': announcement}

    if request.user != announcement.author and not request.user.has_perm('carshare.change_announcement'):
        return redirect('news:index')

    if request.method == "POST":
        form = forms.AnnouncementForm(request.POST, instance=announcement)
        if form.is_valid():
            form.save()
            registrations = models.Registration.objects.filter(announcement=announcement).all()
            users = set(reg.user for reg in registrations if reg.user != request.user)
            notify(
                "L'offre de covoiturage a été éditée",
                "carshare:show", {"aid": announcement.id},
                users
            )
            return redirect(reverse('carshare:show', kwargs={'aid': aid}))
        else:
            context['form'] = form
    else:
        context['form'] = forms.AnnouncementForm(instance=announcement)
    return render(request, 'carshare/edit.html', context)