Пример #1
0
 def change_category(self, action, name):
     """ Add/Del a category """
     if not userinfo.is_admin():
         controller.http_error(403)
     if action == "Add":
         appcat = ApplicationsCategory(name=name)
     else:
         appcat = ApplicationsCategory.query.filter_by(name=name).first()
         if appcat:
             appcat.delete()
     try:
         database.commit()
     except IntegrityError as e:
         pass
Пример #2
0
 def change_category(self, action, name):
     """ Add/Del a category """
     if not userinfo.is_admin():
         controller.http_error(403)        
     if action == "Add":
         appcat = ApplicationsCategory(name = name)
     else:
         appcat = ApplicationsCategory.query.filter_by(name = name).first()
         if appcat:
             appcat.delete();
     try:
         database.commit()
     except IntegrityError as e:
         pass
Пример #3
0
    def edit_submit(self, id, source_package, name, homepage, license, \
        descr, video_link, category):
        """ 
        Add/Edit an application record - submit
        """
        if not userinfo.is_admin():
            controller.http_redirect(controller.base_url() + '/login/')

        # Keep category query on top to avoid autoflush
        cat = ApplicationsCategory.query.filter_by(name=category).first()

        application = app_by_id(id) or Application()
        application.source_package = source_package or None
        application.name = name
        application.homepage = homepage
        application.descr = descr.decode('utf-8')
        application.license = license
        application.video_link = video_link
        if cat:
            application.category = cat
        else:
            return "ERROR: Could not find category", category

        try:
            database.commit()
        except IntegrityError as e:
            session.rollback()
            return "ERROR: Unable to update"

        id = application.id
        # db operation was succesful, update the screenshot if submited
        username = controller.session('login_username')
        filename = os.path.join(apt_portal.base_dir,
                                '../media/screens/%s_upload.png' % username)
        thumb_filename = os.path.join(
            apt_portal.base_dir, '../media/screens/%s_upload_t.png' % username)
        # There is a screenshot image to be uploaded
        if os.path.exists(filename):
            screen_img_dir = os.path.join(apt_portal.base_dir,
                                          "../media/screens/%d" % id)
            if not os.path.isdir(screen_img_dir):
                os.makedirs(screen_img_dir, 0755)
            dest = "%s/%s.png" % (screen_img_dir, id)
            thumb_dest = "%s/%d_t.png" % (screen_img_dir, id)
            os.rename(filename, dest)
            os.chmod(dest, 0644)
            os.rename(thumb_filename, thumb_dest)
            os.chmod(thumb_dest, 0644)
        return "OK " + str(application.id)
Пример #4
0
 def edit_submit(self, id, source_package, name, homepage, license, \
     descr, video_link, category):
     """ 
     Add/Edit an application record - submit
     """
     if not userinfo.is_admin():
         controller.http_redirect(controller.base_url()+'/login/')
             
     # Keep category query on top to avoid autoflush
     cat = ApplicationsCategory.query.filter_by(name=category).first()
     
     application = app_by_id(id) or Application()            
     application.source_package = source_package or None
     application.name = name
     application.homepage = homepage
     application.descr = descr.decode('utf-8')
     application.license = license
     application.video_link = video_link        
     if cat:
         application.category = cat
     else:
         return "ERROR: Could not find category", category                
     
     try:            
         database.commit()
     except IntegrityError as e:
         session.rollback()
         return "ERROR: Unable to update"
     
     id = application.id
     # db operation was succesful, update the screenshot if submited
     username = controller.session('login_username')
     filename = os.path.join(apt_portal.base_dir  , '../media/screens/%s_upload.png' % username)
     thumb_filename = os.path.join(apt_portal.base_dir, '../media/screens/%s_upload_t.png' % username)
     # There is a screenshot image to be uploaded
     if os.path.exists(filename):                
         screen_img_dir  = os.path.join(apt_portal.base_dir, "../media/screens/%d" % id)
         if not os.path.isdir(screen_img_dir):
             os.makedirs(screen_img_dir, 0755)                            
         dest = "%s/%s.png" % (screen_img_dir, id)
         thumb_dest = "%s/%d_t.png" % (screen_img_dir, id)
         os.rename(filename, dest)                
         os.chmod(dest, 0644)                    
         os.rename(thumb_filename, thumb_dest)
         os.chmod(thumb_dest, 0644)    
     return "OK "+str(application.id)
Пример #5
0
def add_admin(username):
    """ Add an username to the admin group """
    from base.models.user import User, UsersGroup
    admin_group = UsersGroup.query.filter_by(name="Admin").first()
    if not admin_group:  # if not found create it
        admin_group = UsersGroup(name="Admin")
    user = User.query.filter_by(username=username).first()
    if not user:
        print "User %s is not registed" % username
        return 2
    if admin_group in user.groups:
        print "User %s is already on the admin group." \
            % username
        return 1
    else:  # add it
        user.groups.append(admin_group)
        user.auth = 1
        database.commit()
        print "User %s added to the admin group." \
            % username
    return 0