Esempio n. 1
0
def create(request):
    if request.method!='POST':
        return HttpResponseRedirect(reverse('manual-index'))
    new_app_form = NewAppForm(request.POST)
    if new_app_form.is_valid():
        applicant = new_app_form.get_applicant()
        applicant.random_password(20)
        # prefix email to prevent e-mail index crash
        applicant.email = "%s-%s" % (random_string(5),applicant.email)

        applicant.is_offline = True

        try:
            applicant.save()

        except IntegrityError:
            # shouldn't happen!
            set_notice_message(request,'ไม่สามารถสร้างได้เนื่องจากอีเมล์ซ้ำ')
            return HttpResponseRedirect(reverse('manual-index'))

        return HttpResponseRedirect(reverse('manual-personal',
                                            args=[applicant.id]))
    
    set_notice_message(request,'ไม่สามารถสร้างได้เนื่องจากข้อมูลผิดพลาด')
    return HttpResponseRedirect(reverse('manual-index'))
Esempio n. 2
0
def populate_upload_field_forms(app_docs, fields, required_fields=None):
    field_forms = {}
    for f in fields:
        field = AppDocs._meta.get_field_by_name(f)[0]

        has_thumbnail = False
        if app_docs!=None:
            field_value = app_docs.__getattribute__(f)
            if (field_value!=None) and (field_value.name!=''):
                has_thumbnail = True

        if (required_fields == None) or (f in required_fields):
            required = True
        else:
            required = False

        field_forms[f] = { 'name': f,
                           'field': field,
                           'required' :required,
                           'has_thumbnail': has_thumbnail,
                           'random_string': random_string(5),
                           'form': FileUploadForm() }
    return field_forms
Esempio n. 3
0
 def random_activation_key(self):
     self.activation_key = random_string(10)
     return self.activation_key
Esempio n. 4
0
 def random_salt(self):
     self.salt = random_string(10)
Esempio n. 5
0
 def random_password(self, length=5):
     import random
     password = random_string(5)
     self.set_password(password)
     return password
Esempio n. 6
0
 def random_string(self):
     try:
         return self._random_string
     except:
         self._random_string = random_string(5)
         return self._random_string
Esempio n. 7
0
 def random_activation_key(self):
     self.activation_key = random_string(10)
     return self.activation_key
Esempio n. 8
0
 def random_salt(self):
     self.salt = random_string(10)
Esempio n. 9
0
 def random_password(self, length=5):
     import random
     password = random_string(5)
     self.set_password(password)
     return password