Пример #1
0
def adminActionRoute(action=None, id=None):
    if not loggedIn():
        return flashy('/', 'You must be logged in to do that!', 'error')
    if not action:
        return flashy('/', 'There was an error processing your request!', 'error')
    if not request.form.get('isact') and not id or id and not id.isdigit(): #Best ifstatement EVAR
        return flashy('/', 'Invalid or maliformed request!', 'error')
    if action == 'delete_proj':
        q = [i for i in Project.select().where(Project.id == int(id))]
        if not len(q):
            return flashy('/', 'Invalid Project ID (%s)' % id, 'error')
        q[0].delete_instance()
        return flashy('/', 'Deleted Project #%s!' % id, 'success')
    elif action == 'add_proj':
        q = [i for i in Project.select().where(Project.name == request.form.get('pname'))]
        if len(q): return flashy('/admin', 'There is already a project with the name "%s"' % request.form.get('pname'), 'error')
        p = Project(
            name=request.form.get('pname'),
            author=User.get(User.id==session.get('uid')),
            desc=request.form.get('pdesc'),
            url=request.form.get('purl'),
            repo_type=request.form.get('repotype'),
            repo_name=request.form.get('pgitname').lower(),
            repo_url=request.form.get('giturl'))
        p.save()
        return flashy('/admin', 'Added project "%s" (ID #%s)' % (p.name, p.id), 'success')
Пример #2
0
 def save_project(self, client, details):
     p = Project(details)
     p.save()