def commissions(request): if request.method == 'GET': form = forms.RequestForm() return render(request, 'commissions.html', {'form': form}) else: form = forms.RequestForm(request.POST) # send mail with the necessary details to me (and maybe a copy to user) if form.is_valid: data = form.data mail_html = render_to_string('mail_commission.html', data) mail_text = ''' %s: %s %s(%s) %s %s %s %s ''' % ( _('Project request'), data['title'], data['name'], data['mail'] + '/' + data['tel'] if data['tel'] else data['mail'], _('proposed the following project:'), data['title'], data['text'], _('This message was sent from christophroyer.com - If you didn\'t use this website, tell me via E-Mail ' '([email protected]) and I will discard your information' )) try: mail = EmailMultiAlternatives( gt('Project request') + ': ' + data.get('title'), mail_text, settings.EMAIL_HOST_USER, [settings.EMAIL_REQUEST_RECIPIENT], reply_to=[data['mail']]) mail.attach_alternative(mail_html, 'text/html') mail.send() if data.get('copy') == 'on': mail_copy = EmailMultiAlternatives( gt('Project request') + ': ' + data.get('title') + '(' + gt('Copy') + ')', mail_text, settings.EMAIL_HOST_USER, [data['mail']], reply_to=[settings.EMAIL_REQUEST_RECIPIENT]) mail_copy.attach_alternative(mail_html, 'text/html') mail_copy.send() except: return HttpResponse( _('Error while sending mail, please try again later'), status=500) return HttpResponse( _('Your request was sent - I\'ll get in touch soon!')) else: return HttpResponse( _('Invalid data - please check your inputs for errors'), status=400)
class UserAdmin(BaseUserAdmin): ordering = ['id'] list_display = ['email', 'name'] fieldsets = ((None, { 'fields': ('email', 'password') }), (gt('Personal info'), { 'fields': ('name', ) }), (gt('Persmissions'), { 'fields': ('is_active', 'is_staff', 'is_superuser') }), (gt('Important dates'), { 'fields': ('last_login', ) })) add_fieldsets = ((None, { 'classes': ('wide', ), 'fields': ('email', 'password1', 'password2') }), )
class UserAdmin(BaseUserAdmin): ordering = ['id'] list_display = ['email', 'name'] # Fields to show in a user's admin detail page fieldsets = ( (None, {'fields': ('email', 'password')}), (gt('Personal Info'), {'fields': ('name',)}), (gt('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser')}), (gt('Important dates'), {'fields': ('last_login',)}), ) # Required fields in order to add a new user on admin's user page add_fieldsets = ( (None, { # Classes is just a way of UI 'classes': ('wide',), # password1 and password2 will appear as password and \ # password confirmation and they will enforce password validation 'fields': ('email', 'password1', 'password2') }), )
def validate(self, attrs): """Validate and authenticate the user""" email = attrs.get('email') password = attrs.get('password') user = authenticate( request=self.context.get('request'), username=email, password=password ) if not user: msg = gt('Unable to authenticate with provided credential') raise serializers.ValidationError(msg, code='authentication') attrs['user'] = user return attrs
def f_overall_price(self): line = str(self.overall_price)[::-1] return " ".join([line[i:i + 3] for i in range(0, len(line), 3) ])[::-1] + " " + gt("сум")
class CustomUserCreationForm(forms.ModelForm): username = forms.CharField( min_length=4, label=_('Username'), max_length=150, help_text=gt('Please fill the form with valid info')) email = forms.EmailField( label=_('Email'), help_text='please file the form with valid email id ') password1 = forms.CharField( label=_("Password"), widget=forms.PasswordInput, min_length=6, help_text= _('<li>Password mast be 6 chareture long all numaric chareture not allowed</li>' )) password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput, min_length=6) # phone = PhoneNumberField(max_length=14,min_length=11,label=_("Phone"),help_text=_('Use this forment +8801*******')) phone = forms.CharField(max_length=14, min_length=11, label=_("Mobile number"), help_text=_('ex: +8801######## or 01#########')) # address=forms.CharField(max_length=200,label=_("Address"),widget=forms.Textarea(attrs={'rows':"2"})) city = forms.ChoiceField(required=True) gender = forms.ChoiceField(choices=[('m', "Male"), ('f', 'Female'), ('o', "Other")], required=True) class Meta: model = User fields = ('username', 'email', 'phone', 'password1', 'password2', 'city', 'gender') # city.choices=[('','-----')]+[(city.name,_(city.name))for city in Citys.objects.all()] # labels = { # 'username': _('Unsername'), # # } # help_texts = { # # 'phone': _('Use this forment +8801777777777'), # "password1":_('Password mast be 8 chareture'), # } def __init__(self, *args, **kwargs): super(CustomUserCreationForm, self).__init__(*args, **kwargs) # print(dir(self.fields['city'])) self.fields['city']._set_choices([('', '-----')] + [(city.name, _(city.name)) for city in Citys.objects.all()]) def clean_username(self): username = self.cleaned_data['username'].lower() r = User.objects.filter(username=username) if r.count(): raise ValidationError("Username already exists") return username def clean_email(self): email = self.cleaned_data['email'].lower() r = User.objects.filter(email=email) if r.count(): raise ValidationError("Email already exists") return email def clean_password2(self): password1 = self.cleaned_data.get('password1') password2 = self.cleaned_data.get('password2') if password1 and password2 and password1 != password2: raise ValidationError("Password don't match") return password2