Esempio n. 1
0
 def renew(self):
     self.last_renew_date = datetime.datetime.today()
     np_date = BSDate.convert_to_bs(
         self.last_renew_date.isoformat()).split('-')
     en_date = BSDate.convert_to_ad('-'.join(
         [str(int(np_date[0]) + 1), '1', '1']))
     self.date_of_expiration = datetime.datetime.strptime(
         en_date, "%Y-%m-%d")
     self.save()
Esempio n. 2
0
    def test_bs_to_ad(self):
        bs_date = "2072-01-10"
        ad_date = "2015-04-23"

        converted_date = BSDate.convert_to_ad(bs_date)
        self.assertEqual(converted_date, ad_date)
Esempio n. 3
0
 def test_invalid_date(self):
     # no 32 in ashoj 2072
     invalid_date = "2072-06-32"
     with self.assertRaises(ValueError):
         BSDate.convert_to_ad(invalid_date)
Esempio n. 4
0
 def test_over_the_range_dates(self):
     over_range_date = "1900-01-10"
     with self.assertRaises(LookupError):
         BSDate.convert_to_ad(over_range_date)
Esempio n. 5
0
 def test_invalid_date(self):
     invalid_date = "2016-02-31"
     with self.assertRaises(ValueError):
         BSDate.convert_to_bs(invalid_date)
Esempio n. 6
0
def get_last_day_of_year():
    date = datetime.date.today()
    np_date = BSDate.convert_to_bs(date.strftime("%Y-%m-%d")).split("-")
    np_year = int(np_date[0]) + 1
    en_date = BSDate.convert_to_ad("-".join([str(np_year), '1', '1']))
    return datetime.datetime.strptime(en_date, "%Y-%m-%d")
Esempio n. 7
0
 def test_wrong_formatting(self):
     wrong_formatted_date = "01-10-2072"
     with self.assertRaises(ValueError):
         BSDate.convert_to_ad(wrong_formatted_date)
Esempio n. 8
0
 def test_invalid_month(self):
     invalid_month = "2015-18-10"
     with self.assertRaises(ValueError):
         BSDate.convert_to_bs(invalid_month)
Esempio n. 9
0
 def test_over_the_range_dates(self):
     over_range_date = "1913-12-29"
     over_range_date = "2044-01-13"
     with self.assertRaises(LookupError):
         BSDate.convert_to_bs(over_range_date)
Esempio n. 10
0
    def test_leap_year_test(self):
        bs_date = "2072-11-19"
        ad_date = "2016-03-02"

        converted_date = BSDate.convert_to_ad(bs_date)
        self.assertEqual(converted_date, ad_date)
Esempio n. 11
0
    def test_bs_to_ad(self):
        bs_date = "2072-01-10"
        ad_date = "2015-04-23"

        converted_date = BSDate.convert_to_ad(bs_date)
        self.assertEqual(converted_date, ad_date)
Esempio n. 12
0
 def test_invalid_date(self):
     # no 32 in ashoj 2072
     invalid_date = "2072-06-32"
     with self.assertRaises(ValueError):
         BSDate.convert_to_ad(invalid_date)
Esempio n. 13
0
 def test_over_the_range_dates(self):
     over_range_date = "1900-01-10"
     with self.assertRaises(LookupError):
         BSDate.convert_to_ad(over_range_date)
Esempio n. 14
0
    def test_leap_year_test(self):
        bs_date = "2072-11-19"
        ad_date = "2016-03-02"

        converted_date = BSDate.convert_to_ad(bs_date)
        self.assertEqual(converted_date, ad_date)
Esempio n. 15
0
 def test_invalid_month(self):
     invalid_month = "2015-18-10"
     with self.assertRaises(ValueError):
         BSDate.convert_to_bs(invalid_month)
Esempio n. 16
0
 def test_over_the_range_dates(self):
     over_range_date = "1913-12-29"
     over_range_date = "2044-01-13"
     with self.assertRaises(LookupError):
         BSDate.convert_to_bs(over_range_date)
Esempio n. 17
0
 def test_invalid_day(self):
     invalid_day = "2015-01-33"
     with self.assertRaises(ValueError):
         BSDate.convert_to_bs(invalid_day)
Esempio n. 18
0
 def test_invalid_day(self):
     invalid_day = "2015-01-33"
     with self.assertRaises(ValueError):
         BSDate.convert_to_bs(invalid_day)
Esempio n. 19
0
 def test_wrong_formatting(self):
     wrong_formatted_date = "01-10-2072"
     with self.assertRaises(ValueError):
         BSDate.convert_to_ad(wrong_formatted_date)
Esempio n. 20
0
 def test_invalid_date(self):
     invalid_date = "2016-02-31"
     with self.assertRaises(ValueError):
         BSDate.convert_to_bs(invalid_date)
Esempio n. 21
0
def addMemberWithArgs(request, created):
    config.refresh()
    form = CreateMemberForm()
    member = None
    if request.method == "POST":
        form = CreateMemberForm(request.POST)
        if form.is_valid():
            # the form is valid, so lets create the member
            data = form.cleaned_data
            if data['first_name'] == '' and data['last_name'] == '':
                created = False
            else:
                first_name = smart_str(data['first_name'].strip(" ").lower())
                last_name = smart_str(data['last_name'].strip(" ").lower())
                gender = smart_str(data['gender'].strip(' ').lower())
                ward_no = smart_str(data['ward_no'].strip(' ').lower())
                tole = smart_str(data['tole'].strip(' ').lower())
                city = smart_str(data['city'].strip(' ').lower())
                home_phone = smart_str(data['home_phone'].strip(' ').lower())
                parent_name = smart_str(data['parent_name'].strip(' ').lower())
                school_name = smart_str(data['school_name'].strip(' ').lower())
                school_class = smart_str(
                    data['school_class'].strip(' ').lower())
                school_number = data['school_number']
                telephone_mobile = data['telephone_mobile']
                roll_no = smart_str(data['roll_no'].strip(' ').lower())
                date_of_birth = data['date_of_birth']
                date_of_expiration = data['date_of_expiration']

                ## creating the username
                username = create_username(first_name, last_name,
                                           ModUser.objects.all().count())
                member = ModUser.objects.create(username=username)
                if first_name not in ['']:
                    member.first_name = first_name
                if last_name not in ['']:
                    member.last_name = last_name
                if gender not in ['']:
                    member.gender = gender
                if ward_no not in ['']:
                    member.addr_ward_no = ward_no
                if tole not in ['']:
                    member.addr_tole = tole
                if city not in ['']:
                    member.addr_municipality = city
                if home_phone not in ['']:
                    member.telephone_home = int(home_phone)
                if parent_name not in ['']:
                    member.parent_name = parent_name
                if school_name not in ['']:
                    member.school_name = school_name
                if school_class not in ['']:
                    member.school_class = school_class
                if roll_no not in ['']:
                    member.school_roll_no = roll_no
                if date_of_birth not in ['']:
                    if date_of_birth.__class__ == str:
                        member.date_of_birth = BSDate.convert_to_ad(
                            date_of_birth)
                    else:
                        member.date_of_birth = date_of_birth
                if date_of_expiration not in ['']:
                    member.date_of_expiration = date_of_expiration
                if school_number not in ['']:
                    member.school_number = school_number
                if telephone_mobile not in ['']:
                    member.telephone_mobile = telephone_mobile
                # school_number and telephone_mobile are not added
                member.groups.add(Group.objects.get(name="Member"))
                member.save()
                created = True

                return HttpResponseRedirect(
                    reverse("addMemberWithArgs", kwargs={"created": created}))

    return render(request,
                  "account/create_member.html",
                  context=addGlobalContext({
                      "form":
                      form,
                      "member_created":
                      created,
                      "member":
                      ModUser.objects.order_by("-date_joined")[0]
                  }))