Example #1
0
    def submit(self, id=None):
        if id == 'new':
            usr = model.CMSUser()
        else:
            usr = model.find_cmsuser(int(id))

        errors = []
        rp = request.POST
        usr.fullname = rp.get('fullname')
        usr.username = rp.get('username')
        if rp.get('password1') and rp.get('password1') == rp.get('password2'):
            usr.password = security.hash_password(rp.get('password1'))

        if id == 'new' and not usr.password:
            errors.append({
                'field': 'password1',
                'message': "een wachtwoord is verplicht bij nieuwe gebruikers"}
            )
        if not usr.username:
            errors.append({'field': 'username',
                           'message': "dit veld moet worden ingevuld"})

        if errors:
            session['post'] = rp
            session['errors'] = errors
            session.save()
            redirect(url.current(action='edit'))

        if id == 'new':
            model.save(usr)
        model.commit()

        return redirect(url(controller='cmsuser', action='list'))
Example #2
0
 def delete(self, id):
     try:
         image = model.findImage(int(id))
         model.delete(image)
         os.unlink(self._pathForImage(id))
         model.commit()
     except Exception, e:
         log.error(str(e))
Example #3
0
    def submit(self, id=None):
        if id == 'new':
            news = model.News()
            news.title = 'Nieuw nieuws'
            news.created = datetime.datetime.now()
            news.active = True
        else:
            news = model.find_news(id)

        rp = request.params
        title = rp.get('title')
        teaser = rp.get('teaser')
        content = rp.get('content')

        errors = []
        if not title:
            errors.append(dict(title='title', message='notempty'))
        if not teaser and not content:
            errors.append(dict(title='teaser', message='notempty'))
            errors.append(dict(title='content', message='notempty'))

        if errors:
            session['errors'] = errors
            session['fields'] = dict(title=title,
                                     teaser=teaser,
                                     content=content)
            session.save()
            redirect(url(controller='news', action='edit', id=id))

        news.title = title
        news.teaser = teaser
        news.content = content
        if id == 'new':
            model.save(news)
        model.commit()

        log.info("Saving new item id=%r;title=%s;created=%s",
                 id,
                 news.title,
                 str(news.created))
        return redirect(url(controller='news', action='list'))
Example #4
0
    def submit(self, id=None):
        if id == 'new':
            news = model.News()
            news.title = 'Nieuw nieuws'
            news.created = datetime.datetime.now()
            news.active = True
        else:
            news = model.find_news(id)

        rp = request.params
        title = rp.get('title')
        teaser = rp.get('teaser')
        content = rp.get('content')

        errors = []
        if not title:
            errors.append(dict(title='title', message='notempty'))
        if not teaser and not content:
            errors.append(dict(title='teaser', message='notempty'))
            errors.append(dict(title='content', message='notempty'))

        if errors:
            session['errors'] = errors
            session['fields'] = dict(title=title,
                                     teaser=teaser,
                                     content=content)
            session.save()
            redirect(url(controller='news', action='edit', id=id))

        news.title = title
        news.teaser = teaser
        news.content = content
        if id == 'new':
            model.save(news)
        model.commit()

        log.info("Saving new item id=%r;title=%s;created=%s", id, news.title,
                 str(news.created))
        return redirect(url(controller='news', action='list'))
Example #5
0
    def submit(self, id=None):
        if id == 'new':
            image = model.Image()
        else:
            image = model.find_image(int(id))

        rp = request.POST
        f = rp.get('image')
        if not os.path.exists(config['pictures_dir']):
            os.makedirs(config['pictures_dir'])

        image.filename = f.filename
        image.filetype = f.type
        image.filesize = len(f.value)
        if id == 'new':
            model.save(image)
        model.commit()

        newfile = self._pathForImage(image.id)
        nf = open(newfile, 'wb')
        shutil.copyfileobj(f.file, nf)

        return redirect(url(controller='picture', action='list'))
Example #6
0
    def submit(self, id=None):
        if id == 'new':
            usr = model.CMSUser()
        else:
            usr = model.find_cmsuser(int(id))

        errors = []
        rp = request.POST
        usr.fullname = rp.get('fullname')
        usr.username = rp.get('username')
        if rp.get('password1') and rp.get('password1') == rp.get('password2'):
            usr.password = security.hash_password(rp.get('password1'))

        if id == 'new' and not usr.password:
            errors.append({
                'field':
                'password1',
                'message':
                "een wachtwoord is verplicht bij nieuwe gebruikers"
            })
        if not usr.username:
            errors.append({
                'field': 'username',
                'message': "dit veld moet worden ingevuld"
            })

        if errors:
            session['post'] = rp
            session['errors'] = errors
            session.save()
            redirect(url.current(action='edit'))

        if id == 'new':
            model.save(usr)
        model.commit()

        return redirect(url(controller='cmsuser', action='list'))
Example #7
0
 def delete(self, id=None):
     news = model.find_news(id)
     log.info("Deleting news item %d %s", news.id, news.title)
     model.delete(news)
     model.commit()
     return redirect(url(controller='news', action='list'))
Example #8
0
 def unhide(self, id=None):
     news = model.find_news(id)
     news.active = True
     model.commit()
     return redirect(url(controller='news', action='list'))
Example #9
0
 def delete(self, id=None):
     news = model.find_news(id)
     log.info("Deleting news item %d %s", news.id, news.title)
     model.delete(news)
     model.commit()
     return redirect(url(controller='news', action='list'))
Example #10
0
 def unhide(self, id=None):
     news = model.find_news(id)
     news.active = True
     model.commit()
     return redirect(url(controller='news', action='list'))
Example #11
0
 def delete(self, id=None):
     if c.cmsuser.id != id:
         usr = model.findCMSUser(int(id))
         model.delete(usr)
         model.commit()
     return redirect(url(controller='cmsuser', action='list'))
Example #12
0
 def delete(self, id=None):
     if c.cmsuser.id != id:
         usr = model.findCMSUser(int(id))
         model.delete(usr)
         model.commit()
     return redirect(url(controller='cmsuser', action='list'))