def handle(request, **kwargs): if 'origin' not in kwargs: pass if 'source' not in kwargs: kwargs['source'] = request_client_ip(request) streams = [] for upload in request.FILES.values(): streams.append(handle_file(upload, **kwargs)) return streams
def handle(path, copy = False, **kwargs): if copy: with open(path, 'rb') as source: return handle_file(source, binary=True, **kwargs) if 'name' not in kwargs: kwargs['name'] = os.path.basename(path) kwargs['source'] = path kwargs['content_path'] = path from hubs.models import Stream stream = Stream(**kwargs) return stream
def upload_misc_file(request, submission_id): submission = get_object_or_404(models.Book, pk=submission_id) if request.POST: file_form = forms.UploadMiscFile(request.POST) if file_form.is_valid(): new_file = handle_file(request.FILES.get('misc_file'), submission, file_form.cleaned_data.get('file_type'), request.user, file_form.cleaned_data.get('label')) submission.misc_files.add(new_file) return redirect(reverse('editor_submission', kwargs={'submission_id': submission.id})) else: file_form = forms.UploadMiscFile() template = 'core/misc_files/upload.html' context = { 'submission': submission, 'file_form': file_form, 'active_page':'editor_submission' } return render(request, template, context)
def email_users(request, group, submission_id=None, user_id=None): submission = get_object_or_404(models.Book, pk=submission_id) editors = logic.get_editors(submission) authors = submission.author.all() onetaskers = submission.onetaskers() to_value="" sent = False if request.POST: print "sS" attachment = request.FILES.get('attachment') subject = request.POST.get('subject') body = request.POST.get('body') to_addresses = request.POST.get('to_values').split(';') cc_addresses = request.POST.get('cc_values').split(';') bcc_addresses = request.POST.get('bcc_values').split(';') to_list=logic.clean_email_list(to_addresses) cc_list=logic.clean_email_list(cc_addresses) bcc_list=logic.clean_email_list(bcc_addresses) if attachment: attachment = handle_file(attachment, submission, 'other', request.user, "Attachment: Uploaded by %s" % (request.user.username)) if to_addresses: if attachment: send_email(subject=subject, context={}, from_email=request.user.email, to=to_list, bcc=bcc_list,cc=cc_list, html_template=body, book=submission, attachment=attachment) else: send_email(subject=subject, context={}, from_email=request.user.email, to=to_list,bcc=bcc_list,cc=cc_list, html_template=body, book=submission) message ="E-mail with subject '%s' was sent." % (subject) return HttpResponse('<script type="text/javascript">window.alert("'+message+'")</script><script type="text/javascript">window.close()</script>') if not group == "all" and user_id: if group == "editors": try: editor = models.User.objects.get(pk=user_id) if editor in editors: to_value="%s;" % (editor.email) else: messages.add_message(request, messages.ERROR, "This editor is not an editor of this submission") except models.User.DoesNotExist: messages.add_message(request, messages.ERROR, "This editor was not found") elif group == "authors": author = get_object_or_404(models.Author, pk=user_id) authors = submission.author.all() if author in authors: to_value="%s;" % (author.author_email) else: messages.add_message(request, messages.ERROR, "This author is not an author of this submission") elif group == "onetaskers": user = get_object_or_404(models.User, pk=user_id) if user in onetaskers: to_value="%s;" % (user.email) else: messages.add_message(request, messages.ERROR, "This onetasker was not found") elif group =="all" and user_id: messages.add_message(request, messages.ERROR, "Cannot use the user field on this page because of the 'all' in the url. Try replacing it with other email groups: 'authors' or 'editors' or 'onetaskers'") group_name=group if not group_name == "editors" and not group_name == "all" and not group_name == "authors" and not group_name == "onetaskers": messages.add_message(request, messages.ERROR, "Group type does not exist. Redirected to page of all groups") return redirect(reverse('email_users', kwargs={'group':'all','submission_id': submission.id})) source = "/email/get/%s/submission/%s/" % (group_name,submission_id) template = 'core/email.html' context = { 'submission': submission, 'from': request.user, 'to_value':to_value, 'source': source, 'group': group_name, 'user_id':user_id, 'sent':sent, } return render(request, template, context)