def index(request): """Request / -- show all posts.""" user = users.GetCurrentUser() posts = Post.CachedGqlToHash("latest_posts","ORDER BY created DESC LIMIT 20") form = PostForm(None) if request.has_key('output') and request['output']=='ajax': return views.respond(request, user, 'posts/_post_list', {'posts': posts}) return views.respond(request, user, 'posts/index', {'posts': posts, 'form' : form})
def edit(request, theme_id): """ This is ripped out of Google's example. This is ugly and I hate it. """ user = users.GetCurrentUser() theme = None editing = False if theme_id: editing = True theme = Theme.theme(theme_id=theme_id) if theme is None: return http.HttpResponseNotFound('No theme exists with that key (%r)' % theme_id) form = ThemeForm(data=request.POST or None, instance=theme) if not request.POST: return respond(request, user, 'themes/new', { 'form': form, 'theme': theme, 'language': 'python', 'code': SNIPPETS['python'] }) errors = form.errors if not errors: try: theme = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err)
def post(self, request): form = forms.PageForm(request.POST) if form.is_valid(): self.category = form.clean_data['category'] category = db.GqlQuery("SELECT * FROM Category WHERE name = :1", self.category).get() if category == None: category = Category(name=self.category, sequence=1) category.put() self.name = form.clean_data['name'] self.sequence = form.clean_data['sequence'] self.content = form.clean_data['content'] self.icon = form.clean_data['icon'] if not self.icon: import re pat = re.compile(r'src=["|\']([^"|\']*)', re.IGNORECASE|re.DOTALL) src = pat.findall(self.content) if src: self.icon = src[0] self.put() return views.viewPage(request, self.category, self.name) else: params = locals() return views.respond(request, 'wiki/wysiwyg.html', params)
def post(self, request): form = forms.PictureForm(request.POST) if form.is_valid(): if form.clean_data['name']: self.name = form.clean_data['name'] else: self.name = request.FILES['filepath']['filename'] self.name = self.name[:-4].capitalize() self.caption = form.clean_data['caption'] tags = form.clean_data['tags'].split(',') self.tags = [tag.strip() for tag in tags] # TODO ComboList/Search try: pfile = request.FILES['filepath'] img = images.Image(pfile['content']) img.im_feeling_lucky() self.data = img.execute_transforms(output_encoding=images.PNG) img.resize(60, 100) self.thumbnail_data = img.execute_transforms(images.PNG) except images.BadImageError: return HttpResponse('Sorry, we had a problem processing the image provided.', mimetype="text/plain") except images.NotImageError: return HttpResponse('Sorry, we don\'t recognize that image format.', mimetype="text/plain") except images.LargeImageError: return HttpResponse('Sorry, the image provided was too large for us to process.', mimetype="text/plain") except: return HttpResponse('Sorry', mimetype="text/plain") self.put() return HttpResponse(self.data, mimetype="image/png") else: params = locals() return views.respond(request, 'wiki/upload.html', params)
def post(self, request): form = forms.CategoryForm(request.POST) if form.is_valid(): self.name = form.clean_data['name'] self.sequence = form.clean_data['sequence'] self.put() return views.respond(request, 'wiki/edit.html', params)
def get(self, request): if self.key: form = forms.PageForm(initial={'name': self.name, 'sequence' : self.sequence, 'category' : self.category, 'content' : self.content, 'icon' : self.icon}) else: form = forms.PageForm() params = {'form': form} return views.respond(request, 'wiki/wysiwyg.html', params)
def post(self, request): form = forms.AuthorForm(request.POST) if form.is_valid(): self.name = form.clean_data['name'] self.email = form.clean_data['email'] self.categories = form.clean_data['categories'] self.put() return views.respond(request, 'wiki/edit.html', {'form' : form})
def get(request, theme_id): user = users.GetCurrentUser() theme = Theme.theme(theme_id=theme_id) lang = 'python' return respond(request, user, 'themes/theme', { 'user': user, 'theme': theme, 'code': tokenize_to_html(SNIPPETS[lang]) })
def show(request,key): """Request / -- show all posts.""" user = users.GetCurrentUser() try: post=Post.get(db.Key(unquote(key))) if post is None: return http.HttpResponseNotFound("No Post exists with that key") return views.respond(request, user, 'posts/show', {'post': post.to_hash()}) except(db.BadKeyError): return http.HttpResponseNotFound("No Post exists with that key")
def new(request): user = users.GetCurrentUser() theme = None form = ThemeDisplayForm(data=request.POST or None, instance=theme) language = 'python' return respond(request, user, 'themes/new', { 'form': form, 'theme': theme, 'language': language, 'code': SNIPPETS[language], })
def edit(request): user=users.GetCurrentUser() if user is None: return http.HttpResponseForbidden('You must be signed in to add or edit a greeting') profile=Profile.gql("where user=:1",user).get() form = ProfileForm(data=request.POST or None, instance=profile) if not request.POST: return views.respond(request, user, 'profiles/form', {'form': form, 'current_profile': profile}) errors = form.errors if not errors: try: profile = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err)
def show(request, nick): user = users.GetCurrentUser() nick=unquote(nick) logging.info('Got key, %s' % nick) profile = Profile.ForNick(nick) if not profile: logging.warn('Nickname missing: %s' % nick) return http.HttpResponseRedirect("/profiles") logging.info('Got profile, %s' % profile.nick) post={} if profile.user!=user: post["body"]="@%s "%profile.nick else: post=None form = PostForm(post) posts=profile.cachedPosts() return views.respond(request, user, 'profiles/show', {'posts': posts, 'profile' : profile,'form':form})
def create(request): data = {} for key in request.POST.keys(): data[key] = request.POST.get(key) user = users.GetCurrentUser() data['uuid'] = str(uuid.uuid4()) form = ThemeForm(data=data) language = request.POST.get('language', 'python') if(form.is_valid()): form.save() return http.HttpResponseRedirect("/themes/%d" % form.instance.key().id()) language = 'python' return respond(request, user, 'themes/new', { 'form': form, 'theme': None, 'language': language, 'code': SNIPPETS[language], })
def list(request, page=1): limit = 6 page = int(page) count = Theme.count() offset = (page-1) * limit num_pages = ceil(float(count) / float(limit)) + 1 current_page = int((float(offset) / float(count)) * num_pages) + 1 user = users.GetCurrentUser() themes = db.GqlQuery('SELECT * FROM Theme ORDER BY created DESC LIMIT %i OFFSET %i'%(limit, offset)) return respond(request, user, 'themes/list', { 'themes': themes, 'user': user, 'num_themes': offset, 'num_pages': num_pages, 'page_range': range(1, num_pages), 'page': page, })
def create(request): """Create a post. GET shows a blank form, POST processes it.""" user = users.GetCurrentUser() if user is None: # Now make them login. # See what we did in websites.py - this should happen here as well. login_url = users.create_login_url(request.get_full_path()) return http.HttpResponseRedirect(login_url) form = PostForm(data=request.POST or None) if not request.POST: return views.respond(request, user, 'posts/create', {'form': form}) errors = form.errors if not errors: try: post = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err)
def edit(request, key): """Edit a post. GET shows a blank form, POST processes it.""" user = users.GetCurrentUser() if user is None: return http.HttpResponseForbidden('You must be signed in to add or edit a post') post = None if key: post=Post.get(db.Key(unquote(key))) if post is None: return http.HttpResponseNotFound("No Post exists with that key") if post.author.user!=user: return http.HttpResponseForbidden('You can only edit your own posts') form = PostForm(data=request.POST or None, instance=post) if not request.POST: return views.respond(request, user, 'posts/edit', {'form': form, 'post': post}) errors = form.errors if not errors: try: post = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err)
form = PostForm(data=request.POST or None) if not request.POST: return views.respond(request, user, 'posts/create', {'form': form}) errors = form.errors if not errors: try: post = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err) if errors: return views.respond(request, user, 'posts/create', {'form': form}) profile=Profile.gql("where user=:1",user).get() if profile is None: profile=Profile.For(user) post.owner = user post.author = profile post.put() profile.increase_count() memcache.delete("latest_posts") profile.clear_post_cache() logging.info('Saved the post, %s' % post) return http.HttpResponseRedirect('/')
def get(self, request): params = {'form': forms.CategoryForm(initial={'name': self.name, 'sequence' : self.sequence})} return views.respond(request, 'wiki/edit.html', params)
def get(self, request): params = {'form': forms.AuthorForm(initial={'name': self.name, 'email': self.email, 'categories': self.categories })} return views.respond(request, 'wiki/edit.html', params)
def get(self, request): params = {'form': forms.PictureForm(initial={'name': self.name, 'caption' : self.caption, 'tags' : self.tags, })} return views.respond(request, 'wiki/upload.html', params)
def index(request): user = users.GetCurrentUser() return respond(request, user, 'home/index', { 'most_downloaded': Theme.most_downloaded(), })
def about(request): user = users.GetCurrentUser() return respond(request, user, 'home/about')
def feedback(request): user = users.GetCurrentUser() return respond(request, user, 'home/feedback')
post=None form = PostForm(post) posts=profile.cachedPosts() return views.respond(request, user, 'profiles/show', {'posts': posts, 'profile' : profile,'form':form}) def edit(request): user=users.GetCurrentUser() if user is None: return http.HttpResponseForbidden('You must be signed in to add or edit a greeting') profile=Profile.gql("where user=:1",user).get() form = ProfileForm(data=request.POST or None, instance=profile) if not request.POST: return views.respond(request, user, 'profiles/form', {'form': form, 'current_profile': profile}) errors = form.errors if not errors: try: profile = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err) if errors: return views.respond(request, user, 'profiles/form', {'form': form, 'current_profile': profile}) profile.put() return http.HttpResponseRedirect('/')
def index(request): """Request / -- show all posts.""" user=users.GetCurrentUser() profiles = Profile.gql("ORDER BY postCount DESC LIMIT 20") return views.respond(request, user, 'profiles/index', {'profiles': profiles})
'theme': theme, 'language': 'python', 'code': SNIPPETS['python'] }) errors = form.errors if not errors: try: theme = form.save(commit=False) except ValueError, err: errors['__all__'] = unicode(err) if errors: return respond(request, user, 'themes/form', { 'form': form, 'theme': theme }) if not theme.author: theme.author = user theme.put() return http.HttpResponseRedirect('/themes/') def create(request): data = {} for key in request.POST.keys(): data[key] = request.POST.get(key) user = users.GetCurrentUser()