Beispiel #1
0
def edit_sortie(request, slug, template_name='sortie/sortie_edit.html'):
    sortie = Sortie.objects.get(titre_slug=slug)
    if request.method == 'POST': # If the form has been submitted...
        preview = request.POST.get('preview', None)
        editpreview = request.POST.get('editpreview', None)
        new_form = SortieForm(request.POST, instance=sortie)
        if not editpreview and new_form.is_valid():
            new_sortie = new_form.save(commit=False)
            if not preview:
                new_sortie.save()
                new_sortie.generate_slug()
                new_sortie.activites.clear()
                for a in request.POST.getlist("activites"):
                    new_sortie.activites.add(a)
                LogActivity.recordActivity(qui=request.user, quoi=new_sortie, comment="a modifi&eacute; l'activit&eacute; <a href='%s'>%s</a>" % (sortie.get_absolute_url(), sortie.titre))
                # Redirect after POST
                return HttpResponseRedirect(sortie.get_absolute_url())
            else:
                cat = Activite.objects.filter(pk__in=request.POST.getlist("activites"))
                return internal_view_sortie(request, new_sortie, urlretour=reverse("editsortie", kwargs={"slug": slug}), categories=cat)
        else:
            form = new_form
    else:
        form = SortieForm(instance=sortie)
    return render_to_response(template_name,
                              RequestContext(request,
                                             {'form': form,
                                              'sortie': sortie,
                                              'full': True,
                                              }))
Beispiel #2
0
def link_galerie(request, template_name='galerie/galerie_link.html'):
    if request.method == 'POST': # If the form has been submitted...
        new_form = LinkGalerieForm(request.POST)
        if new_form.is_valid():
            new_galerie = new_form.save(commit=False)
            new_galerie.generate_slug()
            new_galerie.local_path = os.path.join(settings.TOUPLOAD_ROOT, new_galerie.titre_slug)
            imgur_id = new_galerie.imgur_id
            if imgur_id.startswith("http://"):
                imgur_id = imgur_id[19:]
            if imgur_id.endswith("#0"):
                imgur_id = imgur_id[:-2]
            new_galerie.imgur_id = imgur_id
            new_galerie.save()
            sync_galerie_from_imgur(new_galerie)
            if not request.POST.get('notification'):
                LogActivity.recordActivity(qui=request.user, quoi=new_galerie, comment="a publi&eacute; une nouvelle galerie : <a href='%s'>%s</a>" % (new_galerie.get_absolute_url(), new_galerie.titre))
                ThreadMail(new_galerie).start()
            # Redirect after POST
            return HttpResponseRedirect(new_galerie.get_absolute_url())
        else:
            form = new_form
    else:
        init = {}
        init['auteur'] = request.user.pk
        init['date_publication'] = datetime.datetime.now()
        form = LinkGalerieForm(initial=init)
    return render_to_response(template_name,
                              RequestContext(request,
                                             {'form': form,
                                              'full': True,
                                              }))
Beispiel #3
0
def add_sortie(request, template_name='sortie/sortie_add.html'):
    if request.method == 'POST': # If the form has been submitted...
        preview = request.POST.get('preview', None)
        editpreview = request.POST.get('editpreview', None)
        new_form = SortieForm(request.POST)
        if not editpreview and new_form.is_valid():
            new_sortie = new_form.save(commit=False)
            if not preview:
                new_sortie.save()
                new_sortie.generate_slug()
                new_sortie.activites.clear()
                for a in request.POST.getlist("activites"):
                    new_sortie.activites.add(a)
                LogActivity.recordActivity(qui=request.user, quoi=new_sortie, comment="a ajout&eacute; l'activit&eacute; <a href='%s'>%s</a>" % (new_sortie.get_absolute_url(), new_sortie.titre))
                subscribe_sortie(new_sortie.auteur.get_profile(), new_sortie)
                ThreadMail(new_sortie).start()
                # Redirect after POST
                return HttpResponseRedirect(new_sortie.get_absolute_url())
            else:
                cat = Activite.objects.filter(pk__in=request.POST.getlist("activites"))
                return internal_view_sortie(request, new_sortie, urlretour=reverse("addsortie"), categories=cat)
        else:
            form = new_form
    else:
        init = {}
        init['auteur'] = request.user.pk
        form = SortieForm(initial=init)
    return render_to_response(template_name,
                              RequestContext(request,
                                             {'form': form,
                                              'full': True,
                                              }))
Beispiel #4
0
def create_message(auteur, contenu, thread, isnewthread=False):
    newmessage = Message(auteur=auteur, contenu=contenu, thread=thread)
    newmessage.save()
    LogActivity.recordActivity(qui=auteur, quoi=newmessage, comment="a publi&eacute; un nouveau message : <a href='%s'>%s</a>" % (newmessage.thread.get_absolute_url(), newmessage.thread.titre))
    subscribe_thread_message(newmessage)
    ThreadMail(message=newmessage, isnewthread=isnewthread).start()
    return newmessage
Beispiel #5
0
def edit_article(request, slug, template_name='article/article_edit.html'):
    article = Article.objects.get(titre_slug=slug)
    if request.method == 'POST': # If the form has been submitted...
        preview = request.POST.get('preview', None)
        editpreview = request.POST.get('editpreview', None)
        new_form = ArticleForm(request.POST, instance=article)
        if not editpreview and new_form.is_valid():
            new_article = new_form.save(commit=False)
            if not preview:
                new_article.save()
                new_article.generate_slug()
                LogActivity.recordActivity(qui=request.user, quoi=new_article, comment="a modifi&eacute; l'article : <a href='%s'>%s</a>" % (article.get_absolute_url(), article.titre))
                # Redirect after POST
                return HttpResponseRedirect(article.get_absolute_url())
            else:
                return internal_view_article(request, new_article, urlretour=reverse("editarticle", kwargs={'slug': slug}))
        else:
            form = new_form
    else:
        form = ArticleForm(instance=article)

    return render_to_response(template_name,
                              RequestContext(request,
                                             {'form': form,
                                              'full': True,
                                              'article': article,
                                              }))
Beispiel #6
0
def create_new_article(request, template_name='article/article_add.html'):
    if request.method == 'POST': # If the form has been submitted...
        preview = request.POST.get('preview', None)
        editpreview = request.POST.get('editpreview', None)
        new_form = ArticleForm(request.POST)
        if not editpreview and new_form.is_valid():
            new_article = new_form.save(commit=False)
            if not preview:
                new_article.save()
                new_article.generate_slug()
                LogActivity.recordActivity(qui=request.user, quoi=new_article, comment="a publi&eacute; un nouvel article : <a href='%s'>%s</a>" % (new_article.get_absolute_url(), new_article.titre))
                subscribe_article(new_article.auteur.get_profile(), new_article)
                ThreadMail(new_article).start()
                # Redirect after POST
                return HttpResponseRedirect(new_article.get_absolute_url())
            else:
                return internal_view_article(request, new_article, urlretour=reverse("addarticle"))
        else:
            form = new_form
    else:
        init = {}
        init['auteur'] = request.user.pk
        form = ArticleForm(initial=init)
    return render_to_response(template_name,
                              RequestContext(request,
                                             {'form': form,
                                              'full': True,
                                              }))
Beispiel #7
0
def new_comment(request, pk, type, template_name='comment/new_comment_form.html'):
    article = None
    sortie = None
    galerie = None
    previ = None
    urlredirect = None
    if type == 'article':
        article = Article.objects.get(pk=pk)
        urlredirect = "%s#commentaires-posting" % article.get_absolute_url()
    if type == 'sortie':
        sortie = Sortie.objects.get(pk=pk)
        urlredirect = "%s#commentaires-posting" % sortie.get_absolute_url()
    if type == 'galerie':
        galerie = Galerie.objects.get(pk=pk)
        urlredirect = "%s#commentaires-posting" % galerie.get_absolute_url()
    if type == 'previ':
        previ = Prevision.objects.get(pk=pk)
        urlredirect = "%s#commentaires-posting" % previ.get_absolute_url()
        
    if request.method == 'POST': # If the form has been submitted...
        new_form = CommentForm(request.POST)
        if new_form.is_valid():
            new_comment = new_form.save(commit=False)
            new_comment.save()
            if article:
                article.comments.add(new_comment)
                subscribe_article_comment(new_comment, article)
                LogActivity.recordActivity(qui=request.user, quoi=new_comment, comment="a post&eacute; un nouveau commentaire au sujet de l'article : <a href='%s'>%s</a>" % (article.get_absolute_url(), article.titre), surquoi=article)
            if sortie:
                sortie.comments.add(new_comment)
                subscribe_sortie_comment(new_comment, sortie)
                LogActivity.recordActivity(qui=request.user, quoi=new_comment, comment="a post&eacute; un nouveau commentaire au sujet de l'activit&eacute; : <a href='%s'>%s</a>" % (sortie.get_absolute_url(), sortie.titre), surquoi=sortie)
            if galerie:
                galerie.comments.add(new_comment)
                subscribe_galerie_comment(new_comment, galerie)
                LogActivity.recordActivity(qui=request.user, quoi=new_comment, comment="a post&eacute; un nouveau commentaire au sujet de la galerie : <a href='%s'>%s</a>" % (galerie.get_absolute_url(), galerie.titre), surquoi=galerie)
            if previ:
                previ.comments.add(new_comment)
                LogActivity.recordActivity(qui=request.user, quoi=new_comment, comment="a post&eacute; un nouveau commentaire au sujet de la pr&eacute;vision : <a href='%s'>%s</a>" % (previ.get_absolute_url(), previ), surquoi=previ)
            ThreadMail(new_comment).start()
        # Redirect after POST
        return HttpResponseRedirect(urlredirect)
    else:
        init = {}
        init['auteur'] = request.user.pk
        form = CommentForm(initial=init)
    return render_to_response(template_name,
                              RequestContext(request,
                                             {'form': form,
                                              'type': type,
                                              'pk': pk,
                                              }))
Beispiel #8
0
def _manage_participation(request, slug, statut):
    qui = request.user
    sortie = Sortie.objects.get(titre_slug=slug)
    pp = Participant.objects.filter(qui=qui, sortie=sortie)
    participant = None
    if pp and pp.count() > 0:
        participant = pp[0]

    if not participant:
        participant = Participant(qui=qui, sortie=sortie)
    
    if not participant.statut == statut: 
        participant.statut = statut
        participant.date_update = datetime.datetime.now()
        participant.save()
        subscribe_sortie(qui.get_profile(), sortie)
        LogActivity.recordActivity(qui=qui, quoi=participant, comment="a modifi&eacute; sa participation &agrave; l'activit&eacute; <a href='%s'>%s</a> : %s" % (sortie.get_absolute_url(), sortie.titre, dict(Participant.STATUT)[statut]), surquoi=sortie)
        ThreadParticipationMail(sortie, qui, statut).start()

    return HttpResponseRedirect(sortie.get_absolute_url())
Beispiel #9
0
def edit_sortie_cr(request, slug, template_name='sortie/sortie_edit_cr.html'):
    sortie = Sortie.objects.get(titre_slug=slug)
    first_time = sortie.cr is None

    if request.method == 'POST': # If the form has been submitted...
        preview = request.POST.get('preview', None)
        editpreview = request.POST.get('editpreview', None)
        if first_time:
            new_form = CompteRenduSortieForm(request.POST)
        else:
            new_form = CompteRenduSortieForm(request.POST, instance=sortie.cr)
        if not editpreview and new_form.is_valid():
            new_crsortie = new_form.save(commit=False)
            if first_time:
                new_crsortie.auteur = request.user
            if not preview:
                new_crsortie.save()
                sortie.cr = new_crsortie
                sortie.save()
                if first_time and not request.POST.get('notification'):
                    ThreadCompteRenduMail(sortie, request.user).start()
                LogActivity.recordActivity(qui=request.user, quoi=sortie, comment="a modifi&eacute; le compte-rendu de l'activit&eacute; <a href='%s'>%s</a>" % (sortie.get_absolute_url(), sortie.titre))
                # Redirect after POST
                return HttpResponseRedirect(sortie.get_absolute_url())
            else:
                cat = sortie.activites.all()
                return internal_view_sortie(request, sortie, crsortie=new_crsortie, urlretour=reverse("editsortiecr", kwargs={"slug":slug}), categories=cat)
        else:
            form = new_form
    else:
        if first_time:
            form = CompteRenduSortieForm()
        else:
            form = CompteRenduSortieForm(instance=sortie.cr)
    return render_to_response(template_name,
                              RequestContext(request,
                                             {'form': form,
                                              'sortie': sortie,
                                              'full': True,
                                              }))
Beispiel #10
0
def create_new_user(request, template_name="accounts/user_create_form.html"):
    form = CustomUserCreationForm()
    # if form was submitted, bind form instance.
    if request.method == "POST":
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            # user must be active for login to work
            user.is_active = True
            user.email = request.POST.get("email")
            user.first_name = request.POST.get("first_name")
            user.last_name = request.POST.get("last_name")
            user.save()
            p = Profil(user=user)
            p.last_known_activity = LogActivity.getDefault()
            p.save()

            from_email = "Les Cannes A L'air <*****@*****.**>"
            text = (
                "Nouvel inscrit chez les CAL : %s %s (%s)<br><br>L'invalidation du compte peut se faire <a href='http://cannesalair.fr/admin/auth/user/%s/'>ici</a>."
                % (user.first_name, user.last_name, user.email, user.id)
            )
            to_users = User.objects.filter(groups__name="Admin")
            from core.mail import internal_sendmail

            internal_sendmail(
                ",".join([u.email for u in to_users]),
                from_email,
                text,
                "[CAL] %s vient de s'inscrire sur le site des CAL" % user.username,
                fail_silently=False,
            )
            return HttpResponseRedirect(reverse("editprofil"))

    for f in form.fields:
        if not f == "captcha":
            form.fields[f].widget.attrs["class"] = "input-medium"
        form.fields[f].help_text = ""
    return render_to_response(template_name, RequestContext(request, {"form": form, "isstandalone": True}))
 def forwards(self, orm):
     "Write your forwards methods here."
     activity = LogActivity.getDefault()
     for p in Profil.objects.all():
         p.last_known_activity = activity
         p.save()
Beispiel #12
0
def markasread_notification(request):
    p = request.user.get_profile()
    p.last_known_activity = LogActivity.getDefault()
    p.save()
    return HttpResponseRedirect(reverse("viewnotification")+"?norefresh=1")
Beispiel #13
0
def internal_view_sortie(request, sortie, crsortie=None, template_name='sortie/sortie_view.html', urlretour=None, categories=None):
    date_publication = sortie.date_creation if sortie.date_creation else datetime.datetime.now()
    canbeedited = not urlretour and (request.user == sortie.auteur or request.user.is_superuser)
    if not crsortie:
        crsortie = sortie.cr
    
    caneditcr = canbeedited or (not urlretour and ((crsortie and request.user == crsortie.auteur) or request.user.is_superuser or request.user in [p.qui for p in sortie.participant_sortie_set.filter(statut='oui')]))
    canviewspecificcr = crsortie and request.user.is_authenticated() and (Group.objects.filter(user=request.user, name="Bureau").count() > 0 or request.user.is_superuser or crsortie.auteur == request.user)
    poui = sortie.participant_sortie_set.filter(statut='oui') if sortie.pk else []
    pnon = sortie.participant_sortie_set.filter(statut='non') if sortie.pk else []
    ppe = sortie.participant_sortie_set.filter(statut='peutetre') if sortie.pk else []

    spoui = sortie.participant_special_sortie_set.filter(statut='oui') if sortie.pk else []
    sppe = sortie.participant_special_sortie_set.filter(statut='peutetre') if sortie.pk else []

    totalpe = ppe.count() + sppe.count()
    totalsur = poui.count() + spoui.count()
    totalfull = totalpe + totalsur

    issubscribed = False
    if request.user.is_authenticated() and sortie.pk:
        issubscribed = request.user.get_profile() in sortie.sorties_suivies_set.all()
    
    maparticipation = None
    mesinvites = None
    if request.user.is_authenticated() and sortie.pk:
        maparticipation = Participant.objects.filter(qui=request.user, sortie=sortie)
        mesinvites = SpecialParticipant.objects.filter(sortie=sortie, qui=request.user)
        if maparticipation.count() > 0:
            maparticipation = maparticipation[0]
        else:
            maparticipation = None

    spform = SpecialParticipantForm()
    
    if request.method == 'POST': # If the form has been submitted...
        spform = SpecialParticipantForm(request.POST)
        if spform.is_valid():
            special_participant = spform.save(commit=False)
            special_participant.qui = request.user
            special_participant.sortie = sortie
            special_participant.statut = request.POST.get('statut')
            special_participant.date_update = datetime.datetime.now()
            special_participant.save()
            LogActivity.recordActivity(qui=request.user, quoi=sortie, comment="a ajout&eacute; un(e) participant(e) sp&eacute;cial(e) &agrave; l'activit&eacute; <a href='%s'>%s</a>" % (sortie.get_absolute_url(), sortie.titre))
            # Redirect after POST
            return HttpResponseRedirect(sortie.get_absolute_url())
    
    return render_to_response(template_name, RequestContext(request, 
                                                            {'sortie': sortie,
                                                             'date_publication': date_publication,
                                                             'urlretour': urlretour,
                                                             'canbeedited': canbeedited,
                                                             'crsortie': crsortie,
                                                             'caneditcr': caneditcr,
                                                             'canviewspecificcr': canviewspecificcr,
                                                             'mesinvites': mesinvites,
                                                             'spform': spform,
                                                             'full': True,
                                                             'poui': poui,
                                                             'pouicount': poui.count(),
                                                             'pnon': pnon,
                                                             'pnoncount': pnon.count(),
                                                             'ppe': ppe,
                                                             'ppecount': ppe.count(),
                                                             'spoui': spoui,
                                                             'spouicount': spoui.count(),
                                                             'sppe': sppe,
                                                             'sppecount': sppe.count(),
                                                             'totalfull': totalfull,
                                                             'totalpe': totalpe,
                                                             'totalsur': totalsur,
                                                             'maparticipation': maparticipation,
                                                             'issubscribed': issubscribed,
                                                             'categories': categories,
                                                             }))