Exemple #1
0
 def post(self, offer_id=None, **kwargs):
     """Handle submitted form data"""
     photo = self.request.form.get('photo') or None
     if photo:
         photo = File.get_by_id(int(photo))
     # validate form
     if self.form.validate():
         title = self.form.title.data
         intro = self.form.intro.data
         content = self.form.content.data
         promoted = self.form.promoted.data
         live = self.form.live.data
         language = self.form.language.data
         
         if offer_id:
             offer = Offer.get_by_id(offer_id)
             offer.title = title
             offer.intro = intro
             offer.content = content
             offer.live = live
             offer.promoted = promoted
             offer.language = language
             offer.photo = photo
         # creating new
         else:
             offer = Offer(title=title, intro=intro, content=content, live=live, promoted=promoted, language=language, photo=photo)
         if offer.put():
             return redirect('admin/daily')
     return self.get(**kwargs)
Exemple #2
0
 def get(self, **kwargs):
     offers = Offer.all().order('-modified')
     result = offers.fetch(10)
     context = {
         'offers': result,
     }
     return self.render_response('admin/daily/index.html', **context)
Exemple #3
0
 def get(self, slug=None, **kwargs):
     language = self.get_locale()
     page = Offer.get_by_slug(slug, language=language)
     context = {
         'offer': offer,
         'language': language,
     }
     if page is None:
         return self.redirect_to('notfound')
     return self.render_response('daily/show.html', **context)
Exemple #4
0
 def get(self, **kwargs):
     language = self.get_locale()
     product = Product.get_promoted_product(language=language)
     posts = BlogPost.get_latest_posts(5, language=language)
     offer = Offer.get_latest_offer(language=language)
     context = {
         'product': product,
         'posts': posts,
         'offer': offer,
         'format_currency': i18n.format_currency,
         'language': language,
     }
     return self.render_response('pages/welcome.html', **context)
Exemple #5
0
 def get(self, offer_id=None, **kwargs):
     """Return an offer to edit or an empty form to create"""
     template = 'admin/daily/new.html'
     files = get_files()
     context = {
         'form': self.form,
         'files': files,
     }
     # render edit
     if offer_id is not None:
         offer = Offer.get_by_id(offer_id)
         offer_photo = ''
         if offer.photo:
             offer_photo = offer.photo.key().id()
         if offer:
             self.form = OfferForm(obj=offer)
             context.update({ 'form': self.form, 'offer_photo': offer_photo })
             template = 'admin/daily/edit.html'
         else:
             return redirect('admin/daily/')
     # render new
     return self.render_response(template, **context)