예제 #1
0
    def process_form(self):        
        self.form = forms.BroadcastCouponForm(self.request.POST)   
        if self.form.is_valid():            
            deal_type = int(self.form.cleaned_data['deal_type'])            
            
            coupon_from_date = self.form.cleaned_data['coupon_valid_from_date']            
            coupon_to_date = self.form.cleaned_data['coupon_valid_to_date']
            coupon_valid_all_day = self.form.cleaned_data['valid_all_day']            
            coupon_from_time = self.form.cleaned_data['coupon_valid_from_time'] if not coupon_valid_all_day else datetime.time(0, 0, 0) 
            coupon_to_time = self.form.cleaned_data['coupon_valid_to_time'] if not coupon_valid_all_day else datetime.time(23, 59, 59)            
            coupon_issued_datetime = self.bar.get_now
            coupon_one_per_customer = self.form.cleaned_data['one_per_customer']
                        
            if deal_type == e.DealTypes.SINGLE.key:                
                self.form = forms.BroadcastSingleCouponForm(self.request.POST)
                if self.form.is_valid():
                    coupon_desc = self.form.cleaned_data['coupon_description']
                    coupon = models.SingleCoupon(bar=self.bar, coupon_description=coupon_desc, 
                                                 issued_at=coupon_issued_datetime,
                                                 from_date=coupon_from_date, to_date=coupon_to_date, 
                                                 from_time=coupon_from_time, to_time=coupon_to_time,
                                                 one_per_customer=coupon_one_per_customer)                    
            else:
                self.form = forms.BroadcastGroupCouponForm(self.request.POST)
                if self.form.is_valid():
                    tier_one_min = self.form.cleaned_data['tier_one_min']
                    tier_one_max = self.form.cleaned_data['tier_one_max']
                    tier_one_desc = self.form.cleaned_data['tier_one_desc']
                    tier_two_min= self.form.cleaned_data['tier_two_min'] if self.form.cleaned_data['tier_two_min'] != '' else None
                    tier_two_max= self.form.cleaned_data['tier_two_max'] if self.form.cleaned_data['tier_two_max'] != '' else None
                    tier_two_desc = self.form.cleaned_data['tier_two_desc'] if self.form.cleaned_data['tier_two_desc'] != '' else None
                    
                    coupon = models.GroupCoupon(bar=self.bar, coupon_description=tier_one_desc, 
                                                issued_at=coupon_issued_datetime, 
                                                from_date=coupon_from_date, to_date=coupon_to_date, 
                                                from_time=coupon_from_time, to_time=coupon_to_time, 
                                                tier_one_min=tier_one_min, tier_one_max=tier_one_max, 
                                                tier_two_min=tier_two_min, tier_two_max=tier_two_max,
                                                second_tier_description=tier_two_desc, one_per_customer=coupon_one_per_customer)
                                
            coupon.save()

            DrinkUpEmail('coupon_broadcast', 'New coupon broadcast', h.admin_emails(), context={'coupon' : coupon}).send()
            
            return True
                 
        return False                           
예제 #2
0
def home(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('barwatch.opentapp.barportal.views.logged_in', args=(request.user.id,)))
            
    login_hidden = True
    signup_hidden = True
    signup_success = request.GET.get('signup_success', False)

    login_form = forms.LoginForm()
    signup_form = forms.BarSignupForm({'form_name' : 'signup_form'})        
        
    if request.method == 'POST':
        form_name = request.POST.get('form_name', None)        
        #signup submission        
        if form_name == 'signup_form':            
            signup_form = forms.BarSignupForm(request.POST, request.FILES)            
            if signup_form.is_valid():    
                new_bar = signup_form.save(commit=False)
                username = signup_form.cleaned_data['username']
                password = signup_form.cleaned_data['password']
                email = signup_form.cleaned_data['email']             
    
                (lat, lng) = bar_loc.geocode_address(new_bar.address)
                bar_tz = bar_loc.timezone_by_lat_lng((lat, lng))
                
                new_bar.bar_tz = bar_tz
                new_bar.latitude = str(lat)
                new_bar.longitude = str(lng)
                new_bar.save()
    
                new_user = User.objects.create_user(username, email=email, password=password)
                new_user.save()
                bar_user = models.BarUser(user=new_user, bar=new_bar)
                bar_user.save()
    
                mail_all = [DrinkUpEmail('registration_received', 'Thanks for signing up, we\'ve got your request', [new_user.email])]
                mail_all.append(DrinkUpEmail('registration_received_admin', 'Bar request pending', h.admin_emails(),
                    context={'email':new_user.email, 
                             'bar_name':new_bar.name, 
                             'bar_phone':new_bar.phone, 
                             'username':new_user.username, 
                             'menu_submitted':new_bar.raw_menu is not None}))
    
                for mailer in mail_all:
                    mailer.send()
    
                return HttpResponseRedirect(h.url(reverse('opentapp.barportal.views.home'), {'signup_success' : True}))
            else:
                signup_hidden = False
        else:            
            #login submission
            login_form = forms.LoginForm(request.POST)
            if login_form.is_valid():
                username = login_form.cleaned_data['username']
                password = login_form.cleaned_data['password']
    
                user = authenticate(username=username, password=password) 
                login(request, user)
                request.session['user_id'] = request.user.id #we need to hold the original user in the session to make sure they dont try to switch users during the session
    
                return HttpResponseRedirect(reverse('opentapp.barportal.views.logged_in', args=(request.user.id,)))
            else:            
                login_hidden = False         
                
    tpl_vars = {'login_form'       : login_form,
                'login_hidden'     : login_hidden,
                'signup_form'      : signup_form,                
                'signup_hidden'    : signup_hidden,
                'signup_success'   : signup_success,
                'app_name'         : h.parse_config_file().get('app_name')} 
    
    context = RequestContext(request, tpl_vars)    
    return render_to_response('pages/frontpage.html', context)