def save(self,id): u = UserProfile(id=id,name=self.cleaned_data['name'], sex = self.cleaned_data['sex'], birth=self.cleaned_data['birth'], province = self.cleaned_data['province'], city = self.cleaned_data['city'], hometown = self.cleaned_data['hometown'], position=re.sub(r'\n|\r','',decode_data(self.cleaned_data['position'])), skill=re.sub(r'\n|\r','',decode_data(self.cleaned_data['skill'])), favorite=re.sub(r'\n|\r','',decode_data(self.cleaned_data['favorite'])) ) u.save() return u
def query_tag(request): q = request.GET.get('q') q = decode_data(q) result = search_tags(q) return HttpResponse(result, mimetype="text/json")
def article_subject(request,template_name='public/read_subject.html',id=None,s=None): if id and id.isdigit() and s: s = decode_data(str(s)) one = get_one_subject(int(id)) if one: if one.subject==s: page_number = request.GET.get('page') paginator = Paginator(get_some_subject_article_count(int(id)),10) if page_number and page_number.isdigit(): try: page = paginator.page(int(page_number)) pages = paginator.calculate_display_pages(int(page_number)) except EmptyPage: page = paginator.page(1) pages = paginator.calculate_display_pages(1) else: page = paginator.page(1) pages = paginator.calculate_display_pages(1) articles = get_articles_by_subject(int(id),page.start,page.end) subjects = get_subjects() data={'articles':articles,'one':one,'subjects':subjects} return render_to_response(template_name,data,context_instance=RequestContext(request)) else: raise Http404() else: raise Http404() else: raise Http404()
def save(self,user_id,tags,subjects): tag_data,subject_data='','' tag_data,subject_data = process_tags_subjects(tags,subjects,user_id=user_id) t = Topic(user_id=user_id,topic=re.sub(r'\n|\r','<br>',decode_data(self.cleaned_data['topic'])),subject=subject_data,tag=tag_data,more=re.sub(r'\n|\r','<br>',decode_data(self.cleaned_data['more'])),create_time=datetime.now()) t.save() return t
def save(self,user_id): try: a = ArticleComment(article_id=self.cleaned_data['article_id'],user_id=user_id,to_user_id=self.cleaned_data['to_user_id'],content=re.sub(r'\n|\r','',decode_data(self.cleaned_data['comment'])),create_time=datetime.now()) a.save() return a except Exception, e: raise
def save(self,user_id): try: a = TopicComment(topic_id=self.cleaned_data['topic_id'],user_id=user_id,to_user_id=self.cleaned_data['to_user_id'],content=re.sub(r'\n|\r','',decode_data(self.cleaned_data['content'])),create_time=datetime.now()) a.save() t = Topic.objects.filter(id=self.cleaned_data['topic_id']).values('comment_count') #更新评论总数 Topic.objects.filter(id=self.cleaned_data['topic_id']).update(comment_count=t[0]['comment_count']+1,last_update_time=datetime.now()) return a except Exception: return a else: pass finally: pass