def promotion_detail_groups_create_ajax(request,pk,*kwargs): json = MyJson(request) try: promotion = Promotion.objects.get(pk=pk) if not promotion.promotionIsActive(): raise Exception('Promotion is not active') user = Login(request).getUser() groups = promotion.promotionGroups.filter(users__in = [user]) for g in groups.all(): if g.win_date is None and g.active: g.users.remove(user) else: raise Exception('You are in a group that wins the promotion or the promotion is not active') pg,c = PromotionGroup.objects.get_or_create(user = user, promotion = promotion) if c: pg.save() pg.users.add(user) pg.postSave() data = {} json.addData(data) json.addMessage('You create a group with successfull') json.setOk() except Exception,e: json.setError() json.addError(str(e))
def promotion_detail_groups_join_ajax(request,pk,*kwargs): json = MyJson(request) try: promotion = Promotion.objects.get(pk=pk) if not promotion.promotionIsActive(): raise Exception('Promotion is not active') user = Login(request).getUser() if 'group' not in request.POST: raise Exception('Group don\'t exists') #user.promotions = group_id = int( request.POST.get('group',None) ) print group_id groups = promotion.promotionGroups.filter(users__in = [user]) for g in groups.all(): if g.win_date is None and g.active: g.users.remove(user) else: raise Exception('You are in a group that wins the promotion or the promotion is not active') pg = PromotionGroup.objects.get(promotion = promotion, pk=group_id,active=True,win_date__exact = None) pg.users.add(user) pg.postSave() data = {} json.addData(data) json.addMessage('You join with successfull') json.setOk() except Exception,e: json.setError() json.addError(str(e))