Example #1
0
def _q_index(req):
    name = req.get_form_var('name', '')
    content = req.get_form_var('content', '')
    online_date = req.get_form_var('online_date', '')
    upload_file = req.get_form_var("upload_file", None)
    user_ids = []
    extra = {}
    error = None
    if req.get_method() == "POST":
        if not name or not online_date or not upload_file:
            error = 'miss_args'
        if error is None:
            id = Event.new(req.user.id, name, content, online_date, user_ids, extra)
            event = Event.get(id)
            if upload_file:
                error = event.update_photo(upload_file.tmp_filename)
            if not error:
                return req.redirect(event.path)
    return st('/event/edit.html', **locals())
Example #2
0
def remove_photo(req):
    r = {
        'err':'invalid'
    }
    eid = req.get_form_var("eid", None)
    pid = req.get_form_var("pid", None)
    e = Event.get(eid)
    p = EventPhoto.get(pid)
    if e and p and req.user.id and req.get_method() == "POST":
        p.remove()
        r['err'] = 'ok';
    return json.dumps(r)
Example #3
0
def upload(req):
    r = {
        'err':'invalid'
    }
    eid = req.get_form_var("eid", None)
    if eid:
        e = Event.get(eid)
        if e and req.get_method() == "POST" and req.user:
            upload_file = req.get_form_var("upload_file", None)
            id = e.upload(req.user.id, upload_file.tmp_filename)
            if id:
                p = EventPhoto.get(id)
                r['err'] = 'ok'
                r['id'] = p.id
                r['url'] = p.url(Cate.SMALL)
    return json.dumps(r)
Example #4
0
 def events(self, req):
     req.nav = '/events'
     events = Event.gets()
     return st('/event/events.html', **locals())
Example #5
0
def get_sorted_objects():
    cards = Card.gets_all()
    events = Event.gets()
    objects = sorted(cards + events, key=attrgetter('sort_date'))
    return objects
Example #6
0
def _q_lookup(req, name):
    if not ('-' in name and name.lower()[-4:] in ['.jpg','.png','.gif']):
        raise TraversalError("no such photo")
    ftype = name[-3:]
    n = name[:-4]
    if '$' in name:
        n = name[:name.rindex('$')]
    target_id, photo_id, cate = n.split('-')
    print 'p target_id=%s photo_id=%s cate=%s' % (target_id, photo_id, cate)
    data = None

    scale_type = None
    width = None
    height = None

    if cate.startswith("r_"):
        try:
            r, scale_type, sizes = cate.split('_')
            width, height = sizes.split('x')
            width = int(width)
            height = int(height)
            print 'do resize x=%s, y=%s' % (width, height)
        except:
            print 'do resize fail !!!! ', name
        cate = Cate.LARGE

    if target_id.startswith('evc'):
        event = Event.get(target_id.replace('evc',''))
        if event:
            data = event.photo_data(cate)
    elif target_id.startswith('evp'):
        photo = EventPhoto.get(photo_id)
        if photo:
            data = photo.photo_data(cate)
    elif target_id.startswith('bc'):
        blog_comment = BlogComment.get(target_id.replace('bc', ''))
        if blog_comment:
            data = blog_comment.photo_data(cate)
    elif target_id.startswith('b'):
        blog = Blog.get(target_id.replace('b', ''))
        if blog:
            data = blog.photo_data(cate)
    elif target_id.startswith('g'):
        group = Group.get(target_id.replace('g', ''))
        if group:
            data = group.photo_data(cate)
    else:
        if target_id.startswith('_u_'):
            target_id = target_id.replace('_u_', '')
        card = Card.get(target_id)
        if not card:
            card = Card.get_by_ldap(target_id)
        if card:
            data = card.photo_data(photo_id, cate)
    if not data:
        print "no such photo"
        raise TraversalError("no such photo")
    scale_type = SCALES.get(scale_type, None)
    if scale_type:
        configs = {}
        configs[Cate.RESIZE] = {
            'width': width,
            'height': height,
            'scale': scale_type,
            'gif_scale': scale_type,
        }
        data = scale(data, Cate.RESIZE, configs)
    resp = req.response
    resp.set_content_type('image/jpeg')
    resp.set_header('Cache-Control', 'max-age=%d' % (365*24*60*60))
    resp.set_header('Expires', 'Wed, 01 Jan 2020 00:00:00 GMT')
    if 'pragma' in resp.headers:
        del resp.headers['pragma']
    if cate == Cate.ORIGIN:
        resp.set_content_type('application/force-download')
        resp.set_header('Content-Disposition', 'attachment; filename="%s.%s"' % (name, ftype));
    return data
Example #7
0
File: blog.py Project: leonsim/me
 def event(self):
     from webapp.models.event import Event
     eid = self.extra.get('event_id', None)
     if eid:
         return Event.get(eid)
Example #8
0
def _q_lookup(req, name):
    event = Event.get(name)
    if event:
        return EventUI(req, event)
    return TraversalError("no such event")