Exemple #1
0
 def get(self):
     privilege = user.get_user_privileges()
     if Privileges.can_read(privilege):
         guestbook_name = self.request.get('guestbook_name')
         guestbook_name = "default_guestbook" if guestbook_name is None or len(
             guestbook_name) == 0 else guestbook_name
         update = False
         escaped_guestbook_name = None
         if Privileges.can_write(privilege):
             update = True
             guestbook_name = urllib.urlencode(
                 {'guestbook_name': guestbook_name})
             escaped_guestbook_name = cgi.escape(guestbook_name)
         logout_url = user.get_logout_url('/')
         template_values = {
             "update": update,
             "guestbook_name": guestbook_name,
             "escaped_guestbook_name": escaped_guestbook_name,
             "logout_url": logout_url
         }
         template = JINJA_ENVIRONMENT.get_template('index.html')
         self.response.write(template.render(template_values))
     elif Privileges.is_blocked(privilege):
         return_not_on_whitelist_screen(self)
     else:
         return_login_screen(self)
Exemple #2
0
    def post(self):
        privilege = user.get_user_privileges()
        if Privileges.can_write(privilege):
            guestbook_name = self.request.get('guestbook_name')
            guestbook_name = "default_guestbook" if guestbook_name is None or len(
                guestbook_name) == 0 else guestbook_name

            greeting = dao.create_greeting(guestbook_name)
            greeting.author = user.get_nickname()
            greeting.content = self.request.get('content')

            photo = self.request.get('img')
            if photo is None or len(photo) == 0:
                greeting = 'No photo supplied.'
                template_values = {
                    "message": greeting,
                    "button_msg": "Try again",
                    "loginout_url": "/"
                }
                template = JINJA_ENVIRONMENT.get_template('empty_index.html')
                self.response.write(template.render(template_values))
                self.response.set_status(400)
            else:
                [photo, metadata] = self.rotate_and_get_metadata(photo)

                if 'GPSLatitude' not in metadata or 'GPSLongitude' not in metadata:
                    greeting = 'No GPS coordinates in the image provided.'
                    template_values = {
                        "message": greeting,
                        "button_msg": "Try again",
                        "loginout_url": "/"
                    }
                    template = JINJA_ENVIRONMENT.get_template(
                        'empty_index.html')
                    self.response.write(template.render(template_values))
                    self.response.set_status(400)
                else:
                    greeting.photo = images.resize(photo, 768, 768)
                    greeting.thumbnail = images.resize(photo, 128, 128)
                    greeting.photo_latitude = metadata['GPSLatitude']
                    greeting.photo_longitude = metadata['GPSLongitude']
                    greeting.photo_datetime = metadata[
                        'DateTime'] if 'DateTime' in metadata else ""
                    greeting.put()

                    MemCacheHandler.update_events_cache(guestbook_name)

                self.redirect(
                    '/?' +
                    urllib.urlencode({'guestbook_name': guestbook_name}))
        elif Privileges.is_blocked(privilege):
            return_not_on_whitelist_screen(self)
        else:
            return_login_screen(self)
Exemple #3
0
    def get(self):
        privilege = user.get_user_privileges()
        if Privileges.can_read(privilege):
            self.response.headers['Content-Type'] = 'application/json'
            guestbook_name = self.request.get('guestbook_name')
            guestbook_name = "default_guestbook" if guestbook_name is None or len(
                guestbook_name) == 0 else guestbook_name

            greetings = MemCacheHandler.get_all_events(guestbook_name)
            self.response.out.write(json.dumps(greetings))
        elif Privileges.is_blocked(privilege):
            return_not_on_whitelist_screen(self)
        else:
            return_login_screen(self)
Exemple #4
0
 def get(self):
     privilege = user.get_user_privileges()
     if Privileges.can_read(privilege):
         photo_type = self.request.get('type')
         [thumbnail,
          photo] = MemCacheHandler.get_images_and_update_image_cache(
              self.request.get('img_id'))
         if thumbnail is not None and photo is not None:
             self.response.headers['Content-Type'] = 'image/png'
             if photo_type == "thumbnail":
                 self.response.out.write(thumbnail)
             else:
                 self.response.out.write(photo)
         else:
             self.set_status(404)
             self.response.out.write('No image')
     elif Privileges.is_blocked(privilege):
         return_not_on_whitelist_screen(self)
     else:
         return_login_screen(self)
Exemple #5
0
from user import Admin, Privileges

lead_admin = Admin('Zhenhua', 'Xu', 'Male', 30)
lead_admin.show_privileges()
admin_main = Privileges()
admin_main.show_privileges()
Exemple #6
0
#coding=gbk
from user import Admin,Privileges

privileges = ['can add post','can delete post','can ban user'];
pri = Privileges(privileges);
admin = Admin('guoying','ma','�������������',pri);
admin.show_privileges();
Exemple #7
0
#9-11
from user import Privileges
from user import Admin

god = Admin('Jesus', 'Christ', Privileges(['read', 'write', 'ove']))
god.privileges.show_privileges()
god.desc()
god.greetings()
god.inc_cnt()
god.inc_cnt()
god.inc_cnt()
god.desc()
 def __init__(self, first_name, last_name, gender, age):
     super(Admin, self).__init__(first_name, last_name, gender, age)
     self.privileges = Privileges()
Exemple #9
0
#-*-coding:utf-8-*-
from user import Admin, Privileges

jack = Privileges()
jack.show_privileges()