def save_item(request, *args, **kwargs): result = {} logging.info('item_id: %s', request.get('item_id')) if request.get('item_id'): link = Link.get(request.get('item_id')) else: link = Link() link.created = datetime.datetime.now() link.created_day = datetime.date.today().day link.created_month = datetime.date.today().month link.created_year = datetime.date.today().year link.owner = users.get_current_user().user_id() link.link = request.get('link') link.description = request.get('description') link.is_actual = request.get('is_actual') == '1' link.put() _update_search_index(link, request.get('tags')) #saving tags for tag in LinkTag.all().filter('link = ', link): tag.delete() if request.get('tags'): tags = request.get('tags').split(',') for tag_name in tags: tag_name = tag_name.strip() if len(tag_name): tag = Tag.gql('where name=:1',tag_name).get() if tag == None: tag = Tag(name=tag_name).put() LinkTag(link=link, tag=tag, is_actual=link.is_actual, owner=link.owner).put() result['ok'] = 1 return webapp2.Response(json.dumps(result), content_type='application/json')
def show_list_by_tag(request, *args, **kwargs): tag = Tag.gql('where name=:1',kwargs['tag'].decode('utf-8')).get() if tag == None: return _404() params = {} params['page'] = request.get('page') params['tag'] = tag return _get_list_and_render(params, 'список ссылок по тэгу')
def index(request): tags=memcache.get('tags::1') if tags is None: tags=Tag.gql("WHERE depth = :1", 1) memcache.set('tags::1', tags) if request.user.is_anonymous(): marked_tags=None else: marked_tags=request.user.get_tags() return render_to_response('tasteofhome/index.html', {'tags': tags, 'marked_tags': marked_tags})
def tag(request, key): tag=memcache.get(key) if tag is None: tag=db.get(key) memcache.set(key, tag) tags=memcache.get(key+'::children') if tags is None: tags=Tag.gql("WHERE ANCESTOR IS :1 AND depth = :2", tag, tag.depth+1) memcache.set(key+'::children', tags) if request.user.is_anonymous(): marked_tags=None else: marked_tags=request.user.get_tags() return render_to_response('tasteofhome/tag.html', {'tag': tag, 'tags': tags, 'marked_tags': marked_tags})
def forum_category_page(request, tag, page): discussions=Course.gql("WHERE ANCESTOR IS :1", tag) tags=Tag.gql("WHERE depth = :1", 100) return render_to_response('tasteofhome/forum_category.html', {'discussions': discussions, 'category':tag, 'categories': forum_categories()})
def forum_discussion(request, course): discussion=course tags=Tag.gql("WHERE depth = :1", 100) form=MessageForm() return render_to_response('tasteofhome/discussion.html', {'discussion': discussion, 'form':form, 'categories': forum_categories()})
def forum_categories(): categories=memcache.get('forum::categories') if categories is None: categories=Tag.gql("WHERE depth = :1", 100) memcache.set('forum::categories', categories) return categories