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é 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, }))
def sync_galerie(request, slug): galerie = get_galerie_or_404(slug) sync_galerie_from_imgur(galerie) return HttpResponseRedirect(galerie.get_absolute_url())
def forwards(self, orm): "Write your forwards methods here." for g in Galerie.objects.all(): sync_galerie_from_imgur(g)