Beispiel #1
0
 def months(self):
     # Of course we start from the present day (since there could be
     # image scheduled for future days
     c.images = Image.by_day(self.db,
                             descending=True,
                             startkey=day_to_str(datetime.utcnow()))
     return render('/images/months.mako')
Beispiel #2
0
    def accepted(self):
        # Handles the pagination in a really simple way
        startkey = request.GET.get('startkey')
        endkey = request.GET.get('endkey')

        if startkey:
            c.images = list(Image.by_day(self.db, descending=True, startkey=startkey, limit=16))
        elif endkey:
            c.images = list(Image.by_day(self.db, descending=False, startkey=endkey, limit=16))
            c.images.reverse()
        else:
            c.images = list(Image.by_day(self.db, descending=True, limit=16))

        c.nextkey = c.prevkey = None
        if c.images:
            # If it's 16 elements long, save the key to get the next images
            # and remove the last element (which serves just to see the next key)
            if len(c.images) == 16:
                c.nextkey = day_to_str(c.images[-1].day)
                c.images = c.images[:-1]
                
            # If the image is not the first one, then save the key to get the
            # previous images
            if c.images[0].id != list(Image.by_day(self.db, descending=True, limit=1))[0].id:
                c.prevkey = day_to_str(c.images[0].day)

        return render('/admin/accepted.mako')
Beispiel #3
0
    def show(self, day):
        if str_to_day(day) > datetime.utcnow():
            abort(404)
        else:
            """Shows a single image"""
            c.image = list(Image.by_day(self.db, startkey=day))[0]
            
            if (c.image.day != str_to_day(day)):
                abort(404)

            # Gets the older image (if there is one), the startkey is
            # the day of the image and the list is in descending order
            olders = list(Image.by_day(self.db,
                                       descending=True,
                                       limit=2,
                                       startkey=day))
            
            # If there is one store it
            if len(olders) > 1:
                c.older = day_to_str(olders[1].day)
            

            # Same thing, but the list is in ascending order for the
            # newer images
            newers = list(Image.by_day(self.db,
                                       limit=2,
                                       startkey=day))

            # We check that the newer image is not in a future date
            if (len(newers) > 1) and (datetime.utcnow() >= newers[1].day):
                c.newer = day_to_str(newers[1].day)
            
            session['return_to'] = url(controller='images', action='show', day=day)
            
            return render('/images/show.mako')
Beispiel #4
0
    def _doadduser(self):
        user = User()
        
        user.username = c.username = request.params.getone('username')
        user.email = request.params.getone('email')
        user.role = request.params.getone('role')
        
        c.password = generate_password()
        user.password = c.password

        # Sends the email
        send_email(render('/emails/registration.mako'),
                   'Welcome to troppotardi',
                   [user.email])
        
        user.store(self.db)
        
        flash('User added successfully, an email has been sent with the password.')
        redirect(url(controller='admin', action='adduser'))
Beispiel #5
0
    def pending(self):
        c.images = Image.pending_by_time(self.db,
                                         descending=True)

        return render('/admin/pending.mako')
Beispiel #6
0
 def authors(self):
     c.images = Image.by_day(self.db)
     
     return render('/admin/authors.mako')
Beispiel #7
0
    def edit_user(self, id):
        c.user = User.load(self.db, id)
        c.roles = User.roles

        return render('/admin/edit_user.mako')
Beispiel #8
0
 def users(self):
     c.users = User.by_username(self.db, descending=True)
     
     return render('/admin/users.mako')
Beispiel #9
0
 def cp(self):
     return render('/users/cp.mako')
Beispiel #10
0
    def edit(self, id):
        c.image = Image.load(self.db, id)

        return render('/admin/edit.mako')
Beispiel #11
0
 def index(self, page):
     return render('/pages/' + page + '.mako')
Beispiel #12
0
 def xml_list(self):
     c.images = Image.by_day(self.db,
                             descending=True,
                             startkey=day_to_str(datetime.utcnow()))
     return render('/images/xml_list.mako')        
Beispiel #13
0
    def submit(self):
        c.recaptcha_key = config['recaptcha_pubkey']

        return render('/images/submit.mako')
Beispiel #14
0
    def deleted(self):
        c.images = Image.deleted_by_time(self.db, descending=True)

        return render('/admin/deleted.mako')
Beispiel #15
0
    def adduser(self):
        c.roles = User.roles

        return render('/admin/adduser.mako')
Beispiel #16
0
    def store(self, db, image_file=None):
        # Record the date of submission and the ip of the submitter
        if not self.submitted:
            self.submitted = datetime.utcnow()
            self.author_ip = visitor_ip()


        if self.accepted:
            if self.day:
                # We check that that's the only image we have that day
                days = Image.by_day(db,
                                    descending=False,
                                    startkey=day_to_str(self.day),
                                    endkey=day_to_str(self.day),
                                    )

                # If there is, schedule it, and warn who edited it
                if days and (list(days)[0].id != self.id):
                    flash("The day you selected was already taken, so the photo has been scheduled automatically")
                    self.schedule(db)
            else:
                self.schedule(db)

        # Saves the email only if the image is accepted
        # and if we have an email, of course
        if self.accepted and self.author_email:
            # If there is no previous day, then it means that we are scheduling
            # the image for the first time.
            if not self.prev_day:
                # Saves the email
                tmpl_context.day = self.day
                tmpl_context.author = self.author
                tmpl_context.image_url = pylons_url(str(self.url), qualified=True)
                email = Email(text=render('/emails/accepted.mako'),
                              subject='troppotardi.com',
                              recipients=[self.author_email],
                              )
                email.store(db)
            # Else, we are rescheduling it.
            elif self.prev_day != self.day:
                # Saves the reschedule email
                tmpl_context.day = self.day
                tmpl_context.author = self.author
                tmpl_context.image_url = pylons_url(str(self.url), qualified=True)
                email = Email(text=render('/emails/accepted_again.mako'),
                              subject='troppotardi.com',
                              recipients=[self.author_email],
                              )
                email.store(db)
            # Now we can set the prev_day to the present day
            self.prev_day = self.day

        # If there is a user in the session, store it in the revision
        if 'user' in session:
            self.revised_by = session['user'].id

        # Store it in the database.
        super(Image, self).store(db)

        # Save the image file. We do it afterwards storing the image
        # because we use the id as a filename, and we need to store the image
        # first to get an id.
        if image_file:
            self.store_file(image_file, self.id, db)

        return self
Beispiel #17
0
 def login(self):
     return render('/users/login.mako')