def save(self, commit=True): user = super(UserCreationForm, self).save(commit=False) user.set_password(self.cleaned_data["password1"]) user.email = self.cleaned_data["email"] nickname = self.cleaned_data["nickname"] if commit: user.save() member = Member(nickname=nickname, user=user) member.save() return user
def parse_table(self, url, member): """I am not proud of what is written down here but, at least it works. """ try: request = requests.get(url) except requests.exceptions.RequestException as e: print e return soup = BeautifulSoup(request.content) rows = soup.find_all('tr')[1:] for row in rows: cells = row.find_all('td') # TODO @palcu: fix me !!! try: description = 'Meeting with {0} on {1}.'.format(cells[3].get_text().strip(), cells[4].get_text().strip()) except Exception as e: continue # TODO @palcu: fix me !!! try: date = datetime.strptime(cells[1].get_text().strip(), '%d/%m/%Y') except Exception as e: continue # TODO @palcu: fix me !!! try: memberName = cells[0].get_text().strip() except Exception as e: continue if not Member.objects.filter(name=memberName): memberModel = Member(name=memberName, rank='Cabinet', portofolio=member.portofolio) memberModel.save() print 'saved' else: print 'already saved' memberModel = Member.objects.get(name=memberName) if not Meeting.objects.filter(date=date, description=description): meeting = Meeting(date=date, description=description, member=memberModel, lobby=True) meeting.save()
def member_creation(data): parent = Member.objects.filter(username=data['placement_name']).first() password = generate_password() member_info = { 'username': data.get('username', ''), 'first_name': data.get('first_name', ''), 'last_name': data.get('last_name', ''), 'email': data.get('email', ''), 'sponsor': data.get('sponsor', ''), 'parent': parent, 'placement_name': data.get('placement_name', ''), 'placement_mode': data.get('placement_mode', ''), 'grade': data.get('grade', ''), 'contact': data.get('contact', ''), 'security_code': password } member = Member(**member_info) member.save() return member
def update_members_urls(self): """Parse http://ec.europa.eu/commission/2014-2019/, get the URLs and send them to the database in the members table. Do this every time, because maybe the URLs may have changed. """ try: request = requests.get(BASE_URL) except requests.exceptions.RequestException as e: print e return soup = BeautifulSoup(request.content) bigDiv = soup.find(id='quicktabs-tabpage-team_members-0') members = bigDiv.find_all(class_='views-row') for member in members: url = member.find('a')['href'] photoUrl = member.find('img')['src'] name = member.find(class_='member-details-name').get_text() rank = member.find(class_='role').get_text() portofolio = member.find(class_='member-details-text-2').get_text() if not Portofolio.objects.filter(name=portofolio): portofolioModel = Portofolio(name=portofolio) portofolioModel.save() portofolioModel = Portofolio.objects.get(name=portofolio) if not Member.objects.filter(name=name): memberModel = Member(name=name, photoUrl=photoUrl, rank=rank, portofolio=portofolioModel, url=url) memberModel.save() print 'saved', name else: print 'was already saved', name # Also get the president because he is special if not Member.objects.filter(name='Jean-Claude Juncker'): president = soup.find(class_='team-members-president') url = president.find('a')['href'] photoUrl = president.find('img')['src'] name = 'Jean-Claude Juncker' rank = 'President' portofolioModel = Portofolio(name='President') portofolioModel.save() presidentModel = Member(name=name, photoUrl=photoUrl, rank=rank, portofolio=portofolioModel, url=url) presidentModel.save()
def settings_view(request): try: info = Member.objects.get(user=request.user) except: info = Member(user=request.user) if request.method == 'POST': info_form = MyUserSettingsForm(request.POST, request.FILES, instance=info) password_form = PasswordChangeForm(request.user, request.POST) if info_form.is_valid(): info_form = info_form.save() if password_form.is_valid(): password_form.clean_old_password() password_form = password_form.save() return HttpResponseRedirect("/settings/") else: info_form = MyUserSettingsForm(instance=info) password_form = PasswordChangeForm(request.user, request.GET) return render_to_response("settings.html", { 'info_form': info_form, 'password_form': password_form, }, context_instance=RC(request))
def member_registration(request, data): placement_name = data.get('placement_name', None) pack = data.get('pack', None) delivery_method = data.get('delivery_method', None) payment_mode = data.get('payment_mode', None) pack = Pack.objects.filter(id=int(pack)).first() """1. MEMBER CREATION""" parent = Member.objects.filter(username=placement_name).first() password = generate_password() member_info = { 'username': data.get('username', None), 'first_name': data.get('first_name', None), 'last_name': data.get('last_name', None), 'email': data.get('email', None), 'sponsor': data.get('sponsor', None), 'parent': parent, 'placement_name': data.get('placement_name', None), 'placement_mode': data.get('placement_mode', None), 'grade': "" if pack is None else pack.code, 'paper_id': data.get('paper_id', None), 'gender': data.get('gender', None), 'birth_date': data.get('birth_date', None), 'contact': data.get('contact', None), 'residential_country': data.get('residential_country', None), 'address_1': data.get('address_1', None), 'address_2': data.get('address_2', None), 'post_code': data.get('post_code', None), 'city': data.get('city', None), 'state': data.get('state', None), 'country': data.get('country', None), 'security_code': password } member = Member(**member_info) print("Member => {}".format(member)) member.save() """2. ORDER PROCESS""" sender = request.user.member print("Enroller => {}".format(sender)) operation_data = { 'member': sender, 'wallet': payment_mode, 'sender': sender, 'receiver': member, 'operation': 'registration', 'created_by': sender } operation_status = operation_tnx("m2M", pack.price, **operation_data) print("Operation Data => {}".format(operation_data)) print("Operation Status => {}".format(operation_status)) if operation_status: """3. UPDATE MEMBER STATUS""" member_status_update(member, True) """4. ORDER INFO""" order_tnx_handler(member=member, order_type="P", pack=pack, payment_mode=payment_mode, delivery_method=delivery_method) """5. TEEPS""" teeps_handler(request, pack=pack) """6. SPONSORSHIP BONUS""" sponsorship_bonus_handler(request, sponsor=member.sponsor, pack=pack) """7. TEAM BONUS""" team_bonus_handler(request, pack=pack, member=member, operation="team_bonus") notify_data = { 'action': 'registration', 'e_subject': 'PhytOrganic - Member Registration', 'e_receiver': member.email, 'e_context': { 'username': member.username, 'password': password } } notifier(**notify_data) return True else: return False
def update(cnx, id, name): member = Member.Member(cnx) member.update(( name, id, ))
def create(cnx, name): member = Member.Member(cnx) member.create((name, ))
def search(cnx, searchValue): member = Member.Member(cnx) return member.getAll("%" + searchValue + "%")
def delete(cnx, id): member = Member.Member(cnx) member.delete(id)
def getAll(cnx): member = Member.Member(cnx) return member.getAll()