def calendarCreate(request, pk=None): instance = Calendar() instance = Calendar(group_id=pk) form = CalendarForm(request.POST or None, instance=instance) if request.POST and form.is_valid(): form.save() return HttpResponseRedirect(reverse('cal:list_calendar', args=[pk])) return render(request, 'cal/form.html', {'form': form, 'name': "stanza"})
def form_valid(self, form): form.instance.created_by = self.request.user #sets the created_by user to the current one network = form.save(commit=False) network.save() #saves the object, sets the id self.object = network network_cal = Calendar(network=self.object) network_cal.save() messages.success(self.request, self.get_success_message()) return HttpResponseRedirect(self.get_success_url())
def form_valid(self, form): organization = form.save(commit=False) organization.save() #saves the object, sets the id organization.leader.add( self.request.user) #sets the leader user to the current one self.object = organization organization_cal = Calendar( organization=self.object ) #create a new calendar for the organization organization_cal.save() return HttpResponseRedirect(self.get_success_url())
def activate(request, uidb64, token): user = None try: uid = force_text(urlsafe_base64_decode(uidb64)) user = User.objects.get(pk=uid) except (TypeError, ValueError, OverflowError, User.DoesNotExist): messages.error(request, "That activation link did not work") return HttpResponseRedirect(reverse_lazy('login')) if user is not None and account_activation_token.check_token(user, token): user.is_active = True user.save() login(request, user) try: user_cal = Calendar.objects.get(user=user) except Calendar.DoesNotExist: user_cal = Calendar(user=user) user_cal.save() #all of this down to the return statement creates a yearly repeating account anniversary event today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) pattern = rrule(freq=YEARLY, dtstart=today) description = "On this day in " + str( today.year) + ", your account was created!" aa_event = Event(rrule=pattern, all_day=True, start_time=today, end_time=today + timedelta(days=1), event_type='AA', title="Account Anniversary", description=description) aa_event.calendar = user_cal aa_event.save() messages.success(request, "Successfully verified your account!") return HttpResponseRedirect(reverse_lazy('home:main'))
def form_valid(self, form): form.instance.created_by = self.request.user nonprofit = form.save(commit=False) if self.kwargs.get('network'): nonprofit.network = get_object_or_404(Network, slug=self.kwargs['network']) tag_temp_var = form.cleaned_data.get('tags') #this gets the tag data nonprofit.save() #saves the object, sets the id nonprofit.tags.set( tag_temp_var) #saves the previous tag data after the id is created nonprofit.save() self.object = nonprofit network_calendar = Calendar.objects.get(network=self.object.network.id) nonprofit_cal = Calendar(nonprofit=self.object, network_calendar=network_calendar) nonprofit_cal.save( ) #these last three lines create a calendar for this nonprofit messages.success(self.request, self.get_success_message()) return HttpResponseRedirect(self.get_success_url())