def test_email(request): if request.method == 'GET': form = EmailForm() else: form = EmailForm(data=request.POST) if form.is_valid(): form.save() return render_to_response('mail.html', {'form': form})
def patch(self, request, **kwargs): doctor = get_object_or_404(User, pk=kwargs['pk']).doctor data = QueryDict(request.body) form = EmailForm(data, instance=doctor) if form.is_valid(): form.save() doctorJSON = serializers.serialize("json", [doctor]) return HttpResponse(doctorJSON, content_type='application/json') return HttpResponse(status=500)
def editprofile(request): user = User.objects.get(username=request.user) if request.method == "POST": email = request.POST['email'] try: existent_email = User.objects.get(email=email) except: existent_email = None if existent_email: return render(request, 'fhs/editprofile.html',{"existent": True}) form = EmailForm(data=request.POST, instance=request.user) picform = UserProfileForm(data=request.POST, instance=request.user) try: up = UserProfile.objects.get(user=request.user) except: up = None if form.is_valid() and picform.is_valid(): if email: user = form.save(commit=False) user.save() if 'picture' in request.FILES: up.picture = request.FILES['picture'] up.save() return HttpResponseRedirect('/fhs/profile/'+user.username) else: return render(request, 'fhs/editprofile.html',{})
def edit_details(request): user = User.objects.get(username=request.user) if request.method == "POST": email = request.POST['email'] try: existent_email = User.objects.get(email=email) except: existent_email = None if existent_email: return render(request, 'ArtVillage/edit_details.html', {"existent": True}) form = EmailForm(data=request.POST, instance=request.user) try: up = UserProfile.objects.get(user=request.user) except: up = None if form.is_valid(): if email: user = form.save(commit=False) user.save() return HttpResponseRedirect('/profile/' + user.username) else: return render(request, 'ArtVillage/edit_details.html', {}) else: return render(request, 'ArtVillage/edit_details.html', {})
def editprofile(request): user = User.objects.get(username=request.user) if request.method == "POST": email = request.POST['email'] try: existent_email = User.objects.get(email=email) except: existent_email = None if existent_email: return render(request, 'fhs/editprofile.html', {"existent": True}) form = EmailForm(data=request.POST, instance=request.user) picform = UserProfileForm(data=request.POST, instance=request.user) try: up = UserProfile.objects.get(user=request.user) except: up = None if form.is_valid() and picform.is_valid(): if email: user = form.save(commit=False) user.save() if 'picture' in request.FILES: up.picture = request.FILES['picture'] up.save() return HttpResponseRedirect('/fhs/profile/' + user.username) else: return render(request, 'fhs/editprofile.html', {})
def new_automation(request, alert_type): alert_type = get_object_or_404(AlertType, slug=alert_type, unit__in=request.units) if request.method == 'POST': form = EmailForm(request.POST) if form.is_valid(): if AlertEmailTemplate.objects.filter( alerttype=alert_type, hidden=False, threshold=form.cleaned_data['threshold']).count() > 0: errors = form._errors.setdefault("threshold", ErrorList()) errors.append(u'An e-mail with this threshold already exists.') else: f = form.save(commit=False) f.alerttype = alert_type f.created_by = request.user.username f.save() messages.success( request, "Created new automated email for %s." % alert_type.code) l = LogEntry(userid=request.user.username, description="Created new automated email %s." % alert_type.code, related_object=form.instance) l.save() return HttpResponseRedirect( reverse('alerts.views.view_automation', kwargs={'alert_type': alert_type.slug})) else: form = EmailForm() sample_alert = Alert.objects.filter(alerttype=alert_type, hidden=False)[0] email_tags = [("person.name", "The name of the student that has triggered the alert"), ("person.first_name", "The first name of the student."), ("person.last_name", "The last name of the student."), ("person.middle_name", "The middle name of the student."), ("person.emplid", "The student's emplid."), ("person.email", "The student's email."), ("person.title", "The student's title."), ("description", "The description of the alert.")] for k, v in sample_alert.details.iteritems(): email_tags.append(("details." + k, "For example, (" + str(v) + ")")) return render(request, 'alerts/new_automation.html', { 'alert_type': alert_type, 'form': form, 'email_tags': email_tags })
def register(request): # A HTTP POST? if request.method == 'POST': form = EmailForm(request.POST) # Have we been provided with a valid form? if form.is_valid(): # Save the new category to the database. form.save(commit=True) # Now call the index() view. # The user will be shown the homepage. return HttpResponseRedirect('/fb/login/') else: # The supplied form contained errors - just print them to the terminal. print form.errors else: # If the request was not a POST, display the form to enter details. form = EmailForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). return render(request, 'fb/register.html', {'form': form})
def index(request): if request.method == "POST": form = EmailForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.signup_date = timezone.now() post.email_confirmed = True post.save() return redirect('/emailupdate/thanks/') else: form_class = EmailForm return render(request, 'emailupdate/emailupdate.html', { 'form': form_class, })
def email_draft_edit_view(request, pk, email_pk): issue = _get_issue_for_emails(request, pk) email = _get_email_for_issue(issue, email_pk) if not email.state in DRAFT_EMAIL_STATES: return redirect("case-email-list", issue.pk) case_email_address = build_clerk_address(issue, email_only=True) case_emails = get_case_emails(issue) if request.method == "POST": default_data = { "from_address": case_email_address, "state": EmailState.DRAFT, "issue": issue, "sender": request.user, } data = merge_form_data(request.POST, default_data) form = EmailForm(data, instance=email, files=request.FILES) if form.is_valid(): messages.success(request, "Draft saved.") email = form.save() elif request.method == "DELETE": email.delete() messages.success(request, "Draft deleted") return HttpResponse( headers={"HX-Redirect": reverse("case-email-list", args=(pk, ))}) else: form = EmailForm(instance=email) api = MSGraphAPI() sharepoint_docs = api.folder.get_all_files(f"cases/{issue.id}") sharepoint_options = [{ "name": doc["name"], "value": doc["id"] } for doc in sharepoint_docs] context = { "issue": issue, "form": form, "case_emails": case_emails, "email": email, "case_email_address": case_email_address, "is_disabled": email.state != EmailState.DRAFT, "sharepoint_options": sharepoint_options, } return render(request, "case/case/email/draft_edit.html", context)
def new_automation(request, alert_type): alert_type = get_object_or_404(AlertType, slug=alert_type, unit__in=request.units) if request.method == 'POST': form = EmailForm(request.POST) if form.is_valid(): if AlertEmailTemplate.objects.filter(alerttype=alert_type, hidden=False, threshold=form.cleaned_data['threshold']).count() > 0: errors = form._errors.setdefault("threshold", ErrorList()) errors.append(u'An e-mail with this threshold already exists.' ) else: f = form.save(commit=False) f.alerttype = alert_type f.created_by = request.user.username f.save() messages.success(request, "Created new automated email for %s." % alert_type.code) l = LogEntry(userid=request.user.username, description="Created new automated email %s." % alert_type.code, related_object=form.instance) l.save() return HttpResponseRedirect(reverse('alerts.views.view_automation', kwargs={'alert_type':alert_type.slug})) else: form = EmailForm() sample_alert = Alert.objects.filter(alerttype=alert_type, hidden=False)[0] email_tags = [ ("person.name","The name of the student that has triggered the alert"), ("person.first_name", "The first name of the student."), ("person.last_name", "The last name of the student."), ("person.middle_name", "The middle name of the student."), ("person.emplid", "The student's emplid."), ("person.email", "The student's email."), ("person.title", "The student's title."), ("description","The description of the alert.") ] for k, v in sample_alert.details.iteritems(): email_tags.append( ("details."+k, "For example, (" + str(v) + ")") ) return render(request, 'alerts/new_automation.html', { 'alert_type':alert_type, 'form': form, 'email_tags':email_tags })
def save_email_schedule(request, workflow, action, schedule_item): """ Function to handle the creation and edition of email items :param request: Http request being processed :param workflow: workflow item related to the action :param action: Action item related to the schedule :param schedule_item: Schedule item or None if it is new :return: """ # Create the form to ask for the email subject and other information form = EmailForm(data=request.POST or None, instance=schedule_item, columns=workflow.columns.filter(is_key=True)) now = datetime.datetime.now(pytz.timezone(settings.TIME_ZONE)) # Check if the request is GET, or POST but not valid if request.method == 'GET' or not form.is_valid(): # Render the form return render(request, 'scheduler/email.html', { 'action': action, 'form': form, 'now': now }) # We are processing a valid POST request # Check that the email column has correct values (FIX) # correct_emails = all([validate_email(x[col_idx]) for x in data_table]) # Save the schedule item object s_item = form.save(commit=False) # Assign additional fields and save s_item.user = request.user s_item.action = action s_item.type = 'email_send' s_item.status = 0 # Pending s_item.save() # Create the payload to record the event in the log payload = { 'workflow': workflow.name, 'workflow_id': workflow.id, 'action': action.name, 'action_id': action.id, 'execute': s_item.execute.isoformat(), 'subject': s_item.subject, 'email_column': s_item.email_column.name, 'send_confirmation': s_item.send_confirmation, 'track_read': s_item.track_read } # Log the operation if schedule_item: log_type = 'schedule_email_edit' else: log_type = 'schedule_email_create' logs.ops.put(request.user, log_type, workflow, payload) # Notify the user. Show the time left until execution and a link to # view the scheduled events with possibility of editing/deleting. # Successful processing. now = datetime.datetime.now(pytz.timezone(settings.TIME_ZONE)) tdelta = s_item.execute - now return render(request, 'scheduler/email_done.html', { 'tdelta': str(tdelta), 's_item': s_item })
def email_draft_create_view(request, pk): issue = _get_issue_for_emails(request, pk) case_email_address = build_clerk_address(issue, email_only=True) case_emails = get_case_emails(issue) templates = EmailTemplate.objects.filter( Q(topic=issue.topic) | Q(topic="GENERAL")).order_by("-created_at") for template in templates: # Annotate with url qs = request.GET.copy() qs["template"] = template.pk template.url = "?" + qs.urlencode() parent_email = None if request.method == "POST": default_data = { "from_address": case_email_address, "state": EmailState.DRAFT, "issue": issue, "sender": request.user, } data = merge_form_data(request.POST, default_data) form = EmailForm(data, files=request.FILES) if form.is_valid(): email = form.save() messages.success(request, "Draft created") return redirect("case-email-edit", issue.pk, email.pk) else: # It's a GET request. parent_id = request.GET.get("parent") template_id = request.GET.get("template") initial = {} if parent_id: try: parent_email = Email.objects.get(id=parent_id) _process_email_for_display(parent_email) initial["subject"] = parent_email.subject if parent_email.state == EmailState.INGESTED: initial["to_address"] = parent_email.from_address else: initial["to_address"] = parent_email.to_address except Email.DoesNotExist: raise Http404() if template_id: try: template = EmailTemplate.objects.get(id=template_id) initial["text"] = template.text initial["subject"] = template.subject except EmailTemplate.DoesNotExist: raise Http404() form = EmailForm(initial=initial) context = { "issue": issue, "parent_email": parent_email, "form": form, "case_emails": case_emails, "case_email_address": case_email_address, "templates": templates, "is_disabled": False, } return render(request, "case/case/email/draft_create.html", context)