def user_journey(request, user_id, template_name="account/user_journey.html"): from www.journey.interface import JourneyBase user = ub.get_user_by_id(user_id) if not user: raise Http404 is_me = request.user == user jb = JourneyBase() journeys = jb.get_journeys_by_user_id(user_id) # 分页 page_num = int(request.REQUEST.get('page', 1)) page_objs = page.Cpt(journeys, count=10, page=page_num).info journeys = page_objs[0] page_params = (page_objs[1], page_objs[4]) journeys = jb.format_journeys(journeys) return render_to_response(template_name, locals(), context_instance=RequestContext(request))
def modify_activity(self, activity, user, title, content, start_date, end_date, sign_up_end_date, addr, assembly_point, activity_cover=None): try: content = utils.filter_script(content) if not all((title, content, start_date, end_date, sign_up_end_date, addr, assembly_point)): transaction.rollback(using=ACTIVITY_DB) return 99800, dict_err.get(99800) errcode, errmsg = JourneyBase().validate_journey_element( title, content, min_title_len=5) if not errcode == 0: return errcode, errmsg # 检测时间是否正常 errcode, errmsg = self.check_date(start_date, end_date, sign_up_end_date) if not errcode == 0: transaction.rollback(using=ACTIVITY_DB) return errcode, errmsg activity.title = title activity.content = content activity.start_date = start_date activity.end_date = end_date activity.sign_up_end_date = sign_up_end_date if activity_cover: activity.activity_cover = activity_cover activity.addr = addr activity.assembly_point = assembly_point activity.save() # 更新summary self.get_activity_summary_by_id(activity, must_update_cache=True) transaction.commit(using=ACTIVITY_DB) return 0, activity except Exception, e: transaction.rollback(using=ACTIVITY_DB) debug.get_debug_detail(e) return 99900, dict_err.get(99900)
def create_activity(self, user_id, title, content, start_date, end_date, sign_up_end_date, addr, assembly_point, activity_cover): try: content = utils.filter_script(content) if not all( (user_id, title, content, start_date, end_date, sign_up_end_date, activity_cover, addr, assembly_point)): transaction.rollback(using=ACTIVITY_DB) return 99800, dict_err.get(99800) errcode, errmsg = JourneyBase().validate_journey_element( title, content, min_title_len=5) if not errcode == 0: transaction.rollback(using=ACTIVITY_DB) return errcode, errmsg # 检测时间是否正常 errcode, errmsg = self.check_date(start_date, end_date, sign_up_end_date) if not errcode == 0: transaction.rollback(using=ACTIVITY_DB) return errcode, errmsg activity = Activity.objects.create( user_id=user_id, title=title, content=content, start_date=start_date, end_date=end_date, sign_up_end_date=sign_up_end_date, activity_cover=activity_cover, addr=addr, assembly_point=assembly_point) transaction.commit(using=ACTIVITY_DB) return 0, activity except Exception, e: debug.get_debug_detail(e) transaction.rollback(using=ACTIVITY_DB) return 99900, dict_err.get(99900)
def modify_answer(self, answer, user, content): try: content = utils.filter_script(content) if not content: return 99800, dict_err.get(99800) errcode, errmsg = JourneyBase().validate_content(content) if not errcode == 0: return errcode, errmsg answer.content = content answer.save() # 更新summary self.get_answer_summary_by_id(answer, must_update_cache=True) return 0, answer except Exception, e: debug.get_debug_detail(e) return 99900, dict_err.get(99900)
def async_add_journey_view_count(journey_id): ''' @note: 异步更新浏览次数 ''' from www.journey.interface import JourneyBase JourneyBase().add_journey_view_count(journey_id)
def create_answer(self, obj, obj_type, from_user_id, content, ip=None): try: obj_type = str(obj_type) content = utils.filter_script(content) if not all((obj, obj_type, from_user_id, content)): transaction.rollback(using=ANSWER_DB) return 99800, dict_err.get(99800) errcode, errmsg = JourneyBase().validate_content(content) if not errcode == 0: transaction.rollback(using=ANSWER_DB) return errcode, errmsg to_user_id = obj.user_id answer = Answer.objects.create(from_user_id=from_user_id, to_user_id=to_user_id, content=content, obj_id=obj.id, obj_type=obj_type, ip=ip) from_user = UserBase().get_user_by_id(from_user_id) # 添加at信息 if content.find('@') != -1: at_usernicks = utils.select_at(content) for nick in at_usernicks: at_user = UserBase().get_user_by_nick(nick) if at_user: # 自己@自己的关系不进行存储 if at_user.id != from_user_id: AtAnswer.objects.create(answer=answer, user_id=at_user.id) if at_user.id != to_user_id: # 更新@未读消息数 UnreadCountBase().update_unread_count( at_user.id, code='at_answer') # 发送提醒邮件 context = dict(user=from_user, answer=answer) # async_send_email(at_user.email, u'%s 在且行户外回答中@了你' % (from_user.nick, ), utils.render_email_template('email/at.html', context), 'html') # 更新未读消息 if from_user_id != to_user_id: UnreadCountBase().update_unread_count(to_user_id, code='received_answer') # 发送提醒邮件 to_user = UserBase().get_user_by_id(to_user_id) context = dict(user=from_user, answer=answer) # async_send_email(to_user.email, u'%s 在且行户外回答了你的提问' % (from_user.nick, ), utils.render_email_template('email/answer.html', context), 'html') # 更新用户回答统计总数 UserCountBase().update_user_count(user_id=from_user_id, code='user_answer_count') # 更新回答数冗余信息 obj.answer_count += 1 obj.last_answer_time = datetime.datetime.now() obj.save() transaction.commit(using=ANSWER_DB) return 0, answer except Exception, e: debug.get_debug_detail(e) transaction.rollback(using=ANSWER_DB) return 99900, dict_err.get(99900)