def post(self, menu_identifier=None): if menu_identifier is None or not Menu.isRightIdentifier(menu_identifier): self.siteError( SiteErrorType.ERROR_MENU_NOT_EXIST ) return user = self.context['user'].get_current_user() if not user: self.redirect( users.create_login_url("/write/"+menu_identifier ) ) remote_addr = self.request.remote_addr if not remote_addr: self.siteError( getSiteErrorMessage("invalid_access") ) return self.context['menu_id'] = Menu.getMenuIdWithIdentifier( menu_identifier ) self.context['menu_label'] = Menu.getLabel( self.context['menu_id'] ) self.context['menu_identifier'] = menu_identifier if self.context['user'] and User.isUserNeedCaptcha( self.get_current_user() ): entry_form = EntryRecaptchaForm(remote_addr, data=self.request.POST) else: entry_form = EntryForm(data=self.request.POST) if entry_form.is_valid(): # insert # check user User.insertUser(user, remote_addr) menu_id = self.context['menu_id'] Entry.insert( entry_form.cleaned_data['title'], entry_form.cleaned_data['link'], entry_form.cleaned_data['content'], menu_id, user, remote_addr ) self.redirect("/list/"+Menu.getMenuIdentifier( menu_id) ) else: self.createCSRFToken() self.context['entry_form'] = entry_form self.render( "write.html" )
def post(self, entry_index=None): entry = Entry.get_entry(entry_index) if not entry or entry.is_removed: self.siteError( SiteErrorType.ERROR_ENTRY_NOT_EXIST ) return is_spam = self.request.get('is_spam') if is_spam: # block user siteUser = User.getSiteUser( entry.user ) siteUser.status = UserStatus.USER_BANED siteUser.put() site_user_id = siteUser.key().id() # delete user's comment Comment.delete_with_user_id(site_user_id) # delete user's entry Entry.delete_with_user_id(site_user_id) #delete comment for comment in entry.comments: comment.delete() Entry.delete_entry(entry_index) self.redirect( "/admin/entry" )
def get(self): entries = {} entries['news'] = Entry.all().filter('is_removed', False).filter("menu_id", Menu.MENU_NEWS).order("-created_on").fetch(5, 0) entries['free'] = Entry.all().filter('is_removed', False).filter("menu_id", Menu.MENU_FREE).order("-created_on").fetch(5, 0) entries['tips'] = Entry.all().filter('is_removed', False).filter("menu_id", Menu.MENU_TIPS).order("-created_on").fetch(5, 0) entries['qna'] = Entry.all().filter('is_removed', False).filter("menu_id", Menu.MENU_QNA).order("-created_on").fetch(5, 0) self.context['entries'] = entries self.render( "index.html" )
def get(self, menu_identifier=None, cursor=None): if menu_identifier is None or not Menu.isRightIdentifier(menu_identifier): self.siteError( SiteErrorType.ERROR_MENU_NOT_EXIST ) return self.context['menu_id'] = Menu.getMenuIdWithIdentifier( menu_identifier ) self.context['menu_label'] = Menu.getLabel( self.context['menu_id'] ) self.context['menu_identifier'] = menu_identifier LIST_NUMS = 5 if cursor: cursor = urllib.unquote(cursor).decode('utf-8') query = Entry.all() query.filter("menu_id", self.context['menu_id'] ) query.filter("is_removed", False) query.order("-created_on") paging = Paging( query ) paging.setCurrentCursor( cursor ) paging.setLimit( LIST_NUMS ) paging.execute() self.context['paging'] = paging self.render( "list.html" )
def get(self): if self.request.cookies.get('budgeteerIdToken'): budgeteer = Budgeteer.getBudgeteerById(long(self.request.cookies.get('budgeteerIdToken'))) if not budgeteer: self.redirect('/Login') return else: self.redirect('/Login') return entryId = long(self.request.get('entryId')) budgetId = long(self.request.get('budgetId')) budget = Budget.getBudgetById(budgetId) entry = Entry.get_by_id(entryId) my_permission = Budget.getPermissionByBudgeteerId(long(budgeteer.key.id()), budget) if my_permission != "Manager" and my_permission != "Partner": self.error(403) self.response.write("You have no permission to do so") return if not budget or not entry: self.error(403) self.response.write("There is no such entry") return Budget.RemoveEntryFromBudget(entry.key,budget) self.response.write(json.dumps({'status':'OK'}))
def get(self, type, site_user_id, cursor=None): logging.info( type ) if type != "entry" and type != "comment": self.siteError( SiteErrorType.ERROR_INVALID_ACCESS ) return if cursor: cursor = urllib.unquote(cursor).decode('utf-8') self.context['siteUser'] = User.get_by_id( int( site_user_id ) ) if type == "entry": query = Entry.all() query.filter("site_user_id", int( site_user_id) ) query.filter("is_removed", False) query.order("-created_on") elif type == "comment": query = Comment.all() query.filter("site_user_id", int( site_user_id) ) query.order("-created_on") logging.info( query.__dict__ ) paging = Paging( query ) paging.setLimit(10) paging.setCurrentCursor(cursor) paging.execute() self.context['paging'] = paging if type == "entry": self.render( "admin/entry.html" ) elif type == "comment": self.render( "admin/comment.html" )
def getCountUserAmountInBudget(budget,budgeteerKey): count=0.0 for entryKey in budget.entryList: entry = Entry.getEntryByKey(entryKey) if(entry.addedBy==budgeteerKey): count+=entry.amount return count
def get(self, entryId): if self.request.cookies.get('budgeteerIdToken'): budgeteer = Budgeteer.getBudgeteerById(long(self.request.cookies.get('budgeteerIdToken'))) else: self.redirect('/Login') return if not budgeteer: self.redirect('/Login') return entry = Entry.getEntryById(long(entryId)) if entry.addedBy.id() != long(budgeteer.key.id()): self.redirect('/Budgets') return template_params = dict() budgetId = long(self.request.get('budgetId')) tagList = Budget.getTagList(Budget.getBudgetById(budgetId)) tagNameList = [] for tag in tagList: tagNameList += [tag.description] template.register_template_library('web.templatetags.filter_app') template_params['description'] = entry.description template_params['price'] = entry.amount template_params['tag'] = Tag.getTagByKey(entry.tagKey).description template_params['tagList'] = tagNameList template_params['budgetId'] = budgetId template_params['entryId'] = entryId template_params['userName'] = budgeteer.userName html = template.render("web/templates/edit_entry.html", template_params) self.response.write(html)
def post(self, index=None): self.context['index'] = index entry = Entry.get_entry( index ) if not entry or entry.is_removed: self.siteError( getSiteErrorMessage("entry_not_exist") ) return if entry.user != self.context['user'].get_current_user() and not self.user.is_current_user_admin() : self.siteError( getSiteErrorMessage("invalid_access") ) return remote_addr = self.request.remote_addr if not remote_addr: self.siteError( getSiteErrorMessage("invalid_access") ) return entry_form = EntryForm(data=self.request.POST, instance=entry) if entry_form.is_valid(): entry = entry_form.save(commit=False) if entry.link and entry.link.find("http") == -1 : entry.link = "http://" + entry.link entry.put() self.redirect("/entry/"+index) else: self.context['entry_form'] = entry_form self.render( "edit.html" )
def getCountTagAmountInBudget(budget,tagKey): count=0.0 for entryKey in budget.entryList: entry = Entry.getEntryByKey(entryKey) if(entry.tagKey==tagKey): count+=entry.amount return count
def get(self, entry_index=None): entry = Entry.get_entry(entry_index) if not entry or entry.is_removed: self.siteError( SiteErrorType.ERROR_ENTRY_NOT_EXIST ) return self.context['entry'] = entry self.render('admin/delete.html') pass
def get(self): budgeteerId = None if self.request.cookies.get('budgeteerIdToken'): budgeteerId = long(self.request.cookies.get('budgeteerIdToken')) budgeteer = Budgeteer.getBudgeteerById(budgeteerId) if not budgeteer: self.redirect('/Login') return else: self.redirect('/Login') return budgetId = long(self.request.get('budgetId')) # Verify that the user has sufficient permissions if not Budget.hasAddEditEntryPermissions(budgeteerId, budgetId): self.redirect('/Budgets') return # Prepare a list of tag names. description = self.request.get('description') price = self.request.get('price') tagname = self.request.get('tagname') entryId = long(self.request.get('entryId')) # Fetch the entry entry = Entry.getEntryById(entryId) entry.description = description entry.tagKey = Tag.getTagKeyByName(tagname) entry.amount = float(price) entryKey = Entry.updateEntry(entry) if not entryKey: self.error(403) self.response.write('Entry was not successfully submitted') return self.error(200) self.response.write(json.dumps({'status':'OK'})) return
def post(self, comment_id=None): comment_id = int( comment_id ) comment = Comment.get_by_id( comment_id ) if not comment: self.siteError( SiteErrorType.ERROR_COMMENT_NOT_EXIST ) return siteUser = User.getSiteUser( comment.user ) Comment.delete_comment(comment) is_spam = self.request.get('is_spam') if is_spam: siteUser.status = UserStatus.USER_BANED siteUser.put() site_user_id = siteUser.key().id() # delete user's comment Comment.delete_with_user_id(site_user_id) # delete user's entry Entry.delete_with_user_id(site_user_id) self.redirect( '/admin/comment' )
def get(self, menu_identifier=None): LIST_NUMS = 10 query = Entry.all() query.filter("is_removed", False) query.order("-created_on") paging = Paging( query ) paging.setLimit( LIST_NUMS ) paging.execute() self.context['paging'] = paging self.render( "rss.xml" )
def get(self): budgeteerId = None if self.request.cookies.get('budgeteerIdToken'): budgeteerId = long(self.request.cookies.get('budgeteerIdToken')) budgeteer = Budgeteer.getBudgeteerById(budgeteerId) if not budgeteer: self.redirect('/Login') return else: self.redirect('/Login') return budgetId = long(self.request.get('budgetId')) # Verify that the user has sufficient permissions if not Budget.hasAddEditEntryPermissions(budgeteerId, budgetId): self.redirect('/Budgets') return # Prepare a list of tag names. description = self.request.get('description') price = self.request.get('price') tagname = self.request.get('tagname') # Create the entry entry = Entry() entry.description = description entry.tagKey = Tag.getTagKeyByName(tagname) entry.addedBy = budgeteer.key entry.creationDate = datetime.datetime.now() entry.amount = float(price) budget = Budget.getBudgetById(budgetId) message_template = " Has Added a New Entry In {0}".format(budget.budgetName) src_budgeteer_key = Budgeteer.getBudgeteerById(long(budgeteerId)).key src_username = Budgeteer.getBudgeteerById(long(budgeteerId)).userName for participant_budgeteer_id in Budget.getAssociatedBudgeteersId(budget): if long(budgeteerId) != long(participant_budgeteer_id): dst_budgeteer_key = Budgeteer.getBudgeteerById(long(participant_budgeteer_id)).key new_notification = BudgeteerNotification(srcBudgeteer=src_budgeteer_key, dstBudgeteer=dst_budgeteer_key, message=src_username + message_template, link="/Budget/{0}".format(budgetId), read=False) BudgeteerNotification.addNotification(new_notification) entryKey = Budget.addEntryToBudget(entry, Budget.getBudgetById(long(budgetId))) if not entryKey: self.error(403) self.response.write('Entry was not successfully submitted') return self.error(200) self.response.write(json.dumps({'status':'OK'})) return
def get(self, menu_identifier=None): LIST_NUMS = 10 query = Entry.all() query.filter("is_removed", False) query.order("-created_on") paging = Paging( query ) paging.setLimit( LIST_NUMS ) paging.execute() self.context['paging'] = paging self.response.headers['Content-Type'] = "application/xml" from google.appengine.ext.webapp import template path = os.path.join( os.path.dirname(__file__), '../template/sitemap.xml' ) self.response.out.write( template.render( path, self.context ) )
def get(self, index=None): self.context['index'] = index entry = Entry.get_entry( index ) if not entry or entry.is_removed: self.siteError( getSiteErrorMessage("entry_not_exist") ) return if entry.user != self.context['user'].get_current_user() and not self.user.is_current_user_admin() : self.siteError( getSiteErrorMessage("invalid_access") ) return entry_form = EntryForm(instance=entry) self.context['entry_form'] = entry_form self.createCSRFToken() self.render( "edit.html" )
def post(self, index=None): if not self.context['user'].get_current_user(): self.siteError( SiteErrorType.ERROR_INVALID_ACCESS ) return self.context['index'] = index entry = Entry.get_entry( index ) if not entry or entry.is_removed: self.siteError( getSiteErrorMessage("entry_not_exist") ) return remote_addr = self.request.remote_addr if not remote_addr: self.siteError( getSiteErrorMessage("invalid_access") ) return user = self.context['user'].get_current_user() User.insertUser(user, remote_addr) if self.context['user'] and User.isUserNeedCaptcha( self.get_current_user() ): comment_form = CommentRecaptchaForm(self.request.remote_addr, data = self.request.POST) else: comment_form = CommentForm(data = self.request.POST) if comment_form.is_valid(): comment = Comment.insert(entry, comment_form.cleaned_data['content'], user, remote_addr) entry.comment_count = entry.comment_count + 1 entry.updated_on = datetime.datetime.now() entry.put() PagingCursorMasterKey.clearModelKey("Comment") self.redirect("/entry/%s#comment%d"%(index, comment.id())) else: self.createCSRFToken() self.context['entry'] = entry self.context['comment_form'] = comment_form self.render("view.html")
def get(self, cursor=None): LIST_NUMS = 10 if cursor: cursor = urllib.unquote(cursor).decode('utf-8') self.context['siteUser'] = None query = Entry.all() query.filter("is_removed", False) query.order("-created_on") paging = Paging( query ) paging.setCurrentCursor( cursor ) paging.setLimit( LIST_NUMS ) paging.execute() self.context['paging'] = paging self.render( "admin/entry.html" )
def get(self, index): entry = Entry.get_entry(index) if not entry or entry.is_removed: self.siteError( SiteErrorType.ERROR_ENTRY_NOT_EXIST ) return if self.context['user'] and User.isUserNeedCaptcha( self.get_current_user() ): comment_form = CommentRecaptchaForm(self.request.remote_addr) else: comment_form = CommentForm() self.context['comment_form'] = comment_form self.context['entry'] = entry if self.context['user']: self.createCSRFToken() self.render( "view.html" )
def get(self, budgetId): if self.request.cookies.get('budgeteerIdToken'): budgeteer = Budgeteer.getBudgeteerById(long(self.request.cookies.get('budgeteerIdToken'))) if not budgeteer: self.redirect('/Login') return else: self.redirect('/Login') return template.register_template_library('web.templatetags.filter_app') budget = Budget.getBudgetById(long(budgetId)) if budget is None: self.redirect('/Budgets') return template_params = dict() assoc_budgeteers = Budget.getAssociatedBudgeteersId(budget) for entry in budget.entryList: temp_entry = Entry.getEntryByKey(entry) budgeteer_id = long(Budgeteer.getBudgeteerByKey(temp_entry.addedBy).key.id()) if budgeteer_id not in assoc_budgeteers: Budget.removeEntriesByBudgeteerId(budget, budgeteer_id) template_params['chatMessages'] = ChatMessage.getChatMessagesByBudgetId((budgetId)).fetch() template_params['userName'] = budgeteer.userName template_params['userId'] = budgeteer.key.id() template_params['budget'] = Budget.getBudgetById(long(budgetId)) template_params['budgetId'] = budgetId template_params['chatEnabled'] = budget.chatEnabled if Budget.getPermissionByBudgeteerId(long(budgeteer.key.id()), budget) == "Manager": template_params['budgetManager'] = True elif Budget.getPermissionByBudgeteerId(long(budgeteer.key.id()), budget) is None: self.redirect("/Budgets") else: template_params['budgetManager'] = False html = template.render("web/templates/budget.html", template_params) self.response.write(html)
def get(self, cursor=None): siteUser = User.getSiteUser( self.context['user'].get_current_user() ) if not siteUser: siteUser = User.insertUser(self.context['user'].get_current_user(), self.request.remote_addr ) self.context['siteUser'] = siteUser LIST_NUMS = 10 query = Entry.all() query.filter("site_user_id", User.getSiteUserId( self.context['user'].get_current_user() ) ) query.filter("is_removed", False ) query.order("-created_on") paging = Paging( query ) paging.setCurrentCursor( cursor ) paging.setLimit( LIST_NUMS ) paging.execute() self.context['paging'] = paging self.render("user.html")
def getEntryAddedByByKey(value): entry = Entry.getEntryByKey(value) budgeteer = Budgeteer.getBudgeteerById(entry.addedBy.id()) return budgeteer.userName
def getEntryDescriptionByKey(value): entry = Entry.getEntryByKey(value) return entry.description
def getEntryAmountByKey(value): entry = Entry.getEntryByKey(value) if entry.amount %1 == 0: return int(entry.amount) else: return entry.amount
def getEntryTagDescriptionByKey(value): entry = Entry.getEntryByKey(value) tg = Tag.getTagByKey(entry.tagKey) return tg.description
def getEntryCreationDateByKey(value): entry = Entry.getEntryByKey(value) return entry.creationDate