Beispiel #1
0
    def _dologin(self):
        session['user'] = list(User.by_username(self.db)[self.form_result['username']])[0]
        session.save()
        flash('Login successful')

        if 'redirect_to' in session:
            redir_url = session['redirect_to']
            del session['redirect_to']
            session.save()
            redirect(redir_url)
        else:
            redirect(url('home'))
Beispiel #2
0
    def _doedit_user(self, id):
        user = User.load(self.db, id)
        
        user.username = self.form_result.get('username')
        user.email = self.form_result.get('email')
        user.role = self.form_result.get('role')
        
        if self.form_result.get('password'):
            user.password = self.form_result.get('password')

        user.store(self.db)
        
        flash('User successfully edited.')
        redirect(url(controller='admin', action='edit_user', id=id))
Beispiel #3
0
    def _dosubmit(self):
        
        image = Image()
        
        image.author = self.form_result.get('author')
        image.author_url = self.form_result.get('author_url')
        image.author_email = self.form_result.get('email')
        image.text = self.form_result.get('text')

        image_file = self.form_result.get('image_file').file
        image.store(self.db, image_file=image_file)
        
        flash('Image submitted correctly')
        
        return_to(url('last'))
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 _doedit(self, id):
        image = Image.load(self.db, id)
        
        image.author = request.params.getone('author')
        image.author_email = request.params.getone('author_email')
        image.author_url = request.params.getone('author_url')
        image.text = request.params.getone('text')

        # "change_day" is a hidden field that indicates that the date
        # is exposed in the form. we don't change the day if we are
        # setting the image to pending, since this creates problems
        # when detecting if the image has changed date
        if ('change_day' in self.form_result) and request.params.getone('state') == 'accepted':
            image.day = datetime(year=int(self.form_result.get('year')),
                                 month=int(self.form_result.get('month')),
                                 day=int(self.form_result.get('day')))
        
        image.state = self.form_result.get('state')

        image.store(self.db)

        flash('Image successfully edited')
        redirect(url(controller='admin', action='edit', id=id))
Beispiel #6
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 #7
0
    def delete_user(self, id):
        User.load(self.db, id).delete(self.db)

        flash('User deleted.')

        redirect(url(controller='admin', action='users'))
Beispiel #8
0
 def _docp(self):
     session['user'].password = self.form_result.get('newpassword')
     session['user'].store(self.db)
     session.save()
     flash('Changes were successful')
     redirect(url(controller='users', action='cp'))