def handle(self, *args, **options): CustomWeChatView.update_menu() act_btns = CustomWeChatView.get_book_btn().get('sub_button', list()) self.logger.info('Updated %d activities', len(act_btns)) self.logger.info('=' * 32) for idx, act in enumerate(act_btns): self.logger.info('%d. %s (%s)', idx, act.get('name', ''), act.get('key', ''))
def handle(self, *args, **options): CustomWeChatView.update_menu(Activity.objects.filter( status=Activity.STATUS_PUBLISHED, book_end__gt=timezone.now() ).order_by('book_end')) act_btns = CustomWeChatView.get_book_btn().get('sub_button', list()) self.logger.info('Updated %d activities', len(act_btns)) self.logger.info('=' * 32) for idx, act in enumerate(act_btns): self.logger.info('%d. %s (%s)', idx, act.get('name', ''), act.get('key', ''))
def post(self): if not self.request.user: raise ValidateError("you are logout") ides = self.input array = [] for each_id in ides: act = Activity.objects.get(id=each_id) array.append(act) CustomWeChatView.update_menu(array)
def post(self): if not self.request.user.is_authenticated(): raise ValidateError('User has not logged in.') activityList = [] for activity_id in self.input: activity = Activity.get_by_id(activity_id) activity.status = Activity.STATUS_PUBLISHED activity.save() activityList.append(activity) CustomWeChatView.update_menu(activityList)
def post(self): if isinstance(self.input, list) == False: raise InputError('') input_list = self.input act_list = [] for update_id in input_list: act = Activity.objects.get(id=update_id) act_list.append(act) CustomWeChatView.update_menu(act_list) return None
def post(self): if self.request.user.is_authenticated(): list = [] for item in self.input: acti = Activity.objects.filter(id=item).first() list.append(acti) CustomWeChatView.update_menu(list) pass else: raise LoginError('')
def post(self): activity_list = [] for iid in self.input: try: activity = Activity.objects.get(id=iid) except Activity.DoesNotExist: raise NotExistError( "activity menu error: (post) activity not found") activity_list.append(activity) CustomWeChatView.update_menu(activity_list)
def post(self): if not self.request.user.is_authenticated(): raise ValidateError('Sorry, you are not logged in.') # self.check_input('id') try: in_act = self.input activities = Activity.objects.filter(id__in=in_act) CustomWeChatView.update_menu(activities) except Exception as e: raise MenuError('Failed to update menu.')
def post(self): user = self.request.user if user.is_authenticated: activities = [] for id in self.input: activity = Activity.objects.get(id=id) activities.append(activity) CustomWeChatView.update_menu(activities) else: raise ValidateError("请先登录")
def post(self): data = json.loads(self.request.body.decode('utf-8')) idList = data['ids'] nameList = data['names'] activities = [] for idx, id in enumerate(idList): activity = Activity() activity.id = id activity.name = nameList[idx] activities.append(activity) CustomWeChatView.update_menu(activities)
def post(self): if not self.request.user.is_authenticated(): raise LogicError('not authenticate') ret_activities = [] if not self.input: CustomWeChatView.update_menu(ret_activities) for _id in self.input: try: activity = Activity.objects.get(id=_id) except Activity.DoesNotExist: raise LogicError('activity not exist') ret_activities.append(activity) CustomWeChatView.update_menu(ret_activities)
def post(self): """ input: 活动id数组 需要登录 """ if not self.request.user.is_authenticated(): raise ValidateError("admin-user not login!") else: result = [] activity_id_list = self.input for act_id in activity_id_list: act = Activity.get_by_id(act_id) result.append(act) CustomWeChatView.update_menu(result) return
def get(self): # get current existed_ids = CustomWeChatView.get_menu() query_set = Activity.objects.filter(status__gte=0) activities = [] ind = 1 current_time = timezone.now() for item in query_set: if current_time > item.end_time: # 活动已经结束 continue if item.id in existed_ids: activities.append({ 'id': item.id, 'name': item.name, 'menuIndex': ind, }) ind += 1 else: activities.append({ 'id': item.id, 'name': item.name, 'menuIndex': 0, }) return activities
def post(self): if not self.request.user.is_authenticated(): raise ValidateError("Please login!") idList = self.input for i in Activity.objects.filter(status=Activity.STATUS_PUBLISHED): i.status = 0 activityList = [] for id in idList: try: act = Activity.objects.get(id=id) act.status = 1 act.save() activityList.append(act) except: raise ValidateError("no such activity") CustomWeChatView.update_menu(activityList)
def post(self): if not self.request.user.is_authenticated(): raise ValidateError("not login") try: activity_id_list = self.input MenuIdList.set_menu(activity_id_list) activity_list = [] for id in activity_id_list: activity = Activity.objects.get(id=id) activity_list.append(activity) CustomWeChatView.update_menu(activity_list) except Exception as e: raise MenuError("update menu failed")
def get(self): self.activity_ids = CustomWeChatView.get_activity_ids() result = [] for a in Activity.objects.all(): if a.status == Activity.STATUS_PUBLISHED: result.append(self.activity_menu_item(a)) return result
def handle(self, *args, **options): CustomWeChatView.update_menu()
def post(self): activities = [] for i in self.input: act = Activity.objects.get(id=i) activities.append(act) CustomWeChatView.update_menu(activities)
"""WeChatTicket URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.9/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url, include from django.contrib import admin from wechat.views import CustomWeChatView from WeChatTicket.views import StaticFileView urlpatterns = [ url(r'^wechat/?$', CustomWeChatView.as_view()), url(r'^admin/', admin.site.urls), url(r'^api/u/', include('userpage.urls')), url(r'^api/a/', include('adminpage.urls')), url(r'^', StaticFileView.as_view()), ]
def post(self): activities = list() for id in self.input: activities.append(Activity.objects.get(id=id)) CustomWeChatView.update_menu(activities)
def handle(self, *args, **options): CustomWeChatView.get_templates() self.logger.info('Updated templates.')
def test(self): c = Client() c.post('/api/a/login', { 'username': '******', 'password': '******' }) addMenuUrl = '/api/a/activity/menu' id = Activity.objects.get(name='ycdfwzy').id c.post(addMenuUrl, {'idarr': id}) button = CustomWeChatView.get_book_btn()['sub_button'] self.assertEqual(len(button), 1) # check add menu self.postClickMsg['EventKey'] = CustomWeChatView.event_keys['book_header']+str(id) response = c.post(self.Url, trans_dict_to_xml(self.postClickMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertEqual(Activity.objects.get(name = 'ycdfwzy').remain_tickets, 49) tkt = Ticket.objects.get(student_id = self.stuid) self.assertNotEqual(tkt, None) self.assertEqual(tkt.status, Ticket.STATUS_VALID) response = c.post(self.Url, trans_dict_to_xml(self.postTextMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '你已经抢到票了,请不要重复抢票!') #remain = 0 response = c.post(self.Url, trans_dict_to_xml(getDict(self.userid, '抢票 act_remain0')), content_type = 'text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '抱歉,没票啦!') #deleted response = c.post(self.Url, trans_dict_to_xml(getDict(self.userid, '抢票 act_deleted')), content_type = 'text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '未找到该活动') #saved response = c.post(self.Url, trans_dict_to_xml(getDict(self.userid, '抢票 act_saved')), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '未找到该活动!') #act not exsist response = c.post(self.Url, trans_dict_to_xml(getDict(self.userid, '抢票 act_absent')), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '未找到该活动!') #overdue response = c.post(self.Url, trans_dict_to_xml(getDict(self.userid, '抢票 act_overdue')), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '抢票已结束!') #haven't start response = c.post(self.Url, trans_dict_to_xml(getDict(self.userid, '抢票 act_nstart')), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '抢票未开始!')
def post(self): ids = self.input CustomWeChatView.update_menu([Activity.objects.get(id=x) for x in ids])
def post(self): if self.request.user.is_authenticated(): activities = [Activity.objects.get(id=id) for id in self.input] CustomWeChatView.update_menu(activities)
def post(self): activity_list = [] for i in self.input: activity = Activity.objects.get(id=i) activity_list.append(activity) CustomWeChatView.update_menu(activity_list)
def handle(self, *args, **options): CustomWeChatView.update_menu() self.logger.info('Updated menu.')