def details(request, package, version, simple=False, **kwargs): kwargs.setdefault('template_object_name', 'release') release = get_object_or_404(Package, name=package).get_release(version) if not release: raise Http404('Version %s does not exist for %s' % ( version, package, )) if not simple: if not request.user.is_authenticated(): return redirect_to_login(request.get_full_path()) kwargs.setdefault('queryset', user_releases(request.user)) try: return list_detail.object_detail(request, object_id=release.id, **kwargs) except Http404: return HttpResponseForbidden('You do not have sufficient \ permissions to view this package.') else: kwargs.setdefault('queryset', Release.objects.all()) return list_detail.object_detail(request, object_id=release.id, **kwargs)
def send_email(request, object_id): # create email message using generic views msg_text = list_detail.object_detail( request, queryset=Person.objects.all(), template_name="etreg/person_email_text.html", object_id=object_id, mimetype=None) # create email message using generic views msg_html = list_detail.object_detail( request, queryset=Person.objects.all(), template_name="etreg/person_email_html.html", object_id=object_id, mimetype=None) message_text = '' for line in msg_text: if not "Content-Type" in line: message_text += line message_html = '' for line in msg_html: if not "Content-Type" in line: message_html += line # Remove line "Content-Type: text/html; charset=utf-8" # http://stackoverflow.com/questions/1801008/django-html-email-adds-extra-characters-to-the-email-body #message_html = str(message_html).replace('Content-Type: text/html; charset=utf-8', '') #message_html = message_html.replace('X-Object-Type: etreg.person Content-Type: text/html; charset=utf-8 X-Object-Id: ', '') #message_html = message_html.replace('X-Object-Type: etreg.person X-Object-Id: ', '') person = Person.objects.filter(id=object_id) subject = _('Europatreffen Registration') from_email = '*****@*****.**' to_email = person[0].email msg = EmailMultiAlternatives( subject, message_text, from_email, ['*****@*****.**', '*****@*****.**', to_email]) msg.attach_alternative(message_html, "text/html") msg.send() redirect_url = '/etreg/detail/%s/?token=sent' % object_id return HttpResponseRedirect(redirect_url)
def associate(request, object_id, modelname="", **kwargs): if not kwargs.get("template_name"): kwargs["template_name"] = 'csv_detail.html' if not kwargs.get("form_class"): kwargs["form_class"] = CSVAssociateForm if not modelname: raise ValueError( "A model wasn't specified. This is our fault. Please let us know this happened so we can fix it, thanks.") else: kwargs["model"] = eval(modelname) kwargs = prepare_view(request, kwargs) instance = get_object_or_404(CSV, pk=object_id) if request.method == 'POST': form = kwargs["form_class"](instance, request.POST) if form.is_valid(): form.save(request) request.user.message_set.create(message='CSV imported.') return HttpResponseRedirect("/core/%s" % (modelname.lower())) else: messages.info(request, 'Uploaded CSV. Please associate fields below.') form = CSVAssociateForm(instance) kwargs["extra_context"].update({"form": form}) return object_detail(request, queryset=CSV.objects.all(), object_id=object_id, template_name=kwargs["template_name"], template_object_name='csv', extra_context=kwargs["extra_context"], )
def city_detail(request, slug, **kwargs): return list_detail.object_detail( request, queryset = City.objects.all(), slug = slug, **kwargs )
def newsletter_detail(request, newsletter_slug): newsletters = Newsletter.on_site.filter(visible=True) if not newsletters: raise Http404 return list_detail.object_detail(request, newsletters, slug=newsletter_slug)
def org_detail(request, object_id): return object_detail ( request, queryset = Org.objects.all(), object_id = object_id, template_name = 'contact/org_detail.html', )
def talents_detail(request, slug, **kwargs): return list_detail.object_detail( request, queryset=Talents.objects.all(), slug=slug, **kwargs )
def talk(request, scope, id): objects = Talk.objects.filter(approved=True) audience = {} for choice in AUDIENCE_CHOICES: audience[choice[0]] = choice[1] extra_context = dict(choices=audience) return object_detail(request, objects, id, extra_context=extra_context)
def view_account(request, account_id): if not request.user.is_superuser: get_object_or_404(Account, owner=request.user, pk=account_id) else: get_object_or_404(Account, pk=account_id) qss_entries = None qss_transactions = None qs = Account.objects.filter(pk = account_id) transaction_qs = Transaction.objects.filter(entries__account = account_id)\ .annotate(date=Min('entries__date')) if qs: qss_entries = QuerySetStats(qs, 'entries__date') qss_transactions = QuerySetStats(transaction_qs, 'date') return object_detail( request = request, queryset = qs, object_id = account_id, template_name = "account_detail.html", extra_context = { 'qss_entries': qss_entries, 'qss_transactions': qss_transactions, } )
def widget_detail(request, widgetsettings_id): """Widget details page where user can set options defined for the widget """ widget = WidgetSettings.objects.get(pk=widgetsettings_id) opts = widget.get_widget().options(widget) if request.method == "POST": form = options_form(opts)(request.POST) if form.is_valid(): for field in form.cleaned_data: set_option(field, form.cleaned_data[field]) if opts: defaults = [opt.get('default') for opt in opts.values()] initial = get_options(opts.keys(), defaults) form = options_form(opts)(initial=initial) else: form = None extra_context = { 'options_form': form } queryset = WidgetSettings.objects.all() return object_detail(request, queryset, widgetsettings_id, template_name="plugins/widget_detail.html", extra_context=extra_context)
def solution_detail(request, solution_id, full): solution = get_object_or_404(Solution, pk=solution_id) if (not (solution.author == request.user or in_group(request.user, 'Trainer') or (solution.author.tutorial and solution.author.tutorial.tutors.filter(id=request.user.id)))): return access_denied(request) if (request.method == "POST"): solution.copy() return HttpResponseRedirect( reverse('solution_list', args=[solution.task.id])) else: attestations = Attestation.objects.filter( solution__task=solution.task, author__tutored_tutorials=request.user.tutorial) attestationsPublished = attestations[ 0].published if attestations else False return object_detail(request, Solution.objects.all(), solution_id, extra_context={ "attestationsPublished": attestationsPublished, "accept_all_solutions": get_settings().accept_all_solutions, "full": full }, template_object_name='solution')
def index(request): if first_nav: return object_detail(request, Article.objects.all(), slug=first_nav.get_article().slug, extra_context={'nav_headers': nav_headers}) else: raise Http404
def book_detail(request, book_id): return object_detail( request, queryset=Book.objects.all(), object_id=book_id, template_object_name='book', )
def precedent_detail(request, slug): precedents = Precedent.published.all() return object_detail(request, queryset=precedents, slug=slug, template_object_name='project', template_name='portfolio/precedent_detail.html',)
def liaison_detail(request, object_id): if settings.USE_DB_REDESIGN_PROXY_CLASSES: qfilter = Q() public_liaisons = LiaisonDetail.objects.exclude(approved=None).order_by("-submitted_date") else: qfilter = Q(approval__isnull=True)|Q(approval__approved=True) public_liaisons = LiaisonDetail.objects.filter(qfilter).order_by("-submitted_date") liaison = get_object_or_404(public_liaisons, pk=object_id) can_edit = False user = request.user can_take_care = _can_take_care(liaison, user) if user.is_authenticated() and can_edit_liaison(user, liaison): can_edit = True if request.method == 'POST' and request.POST.get('do_action_taken', None) and can_take_care: liaison.action_taken = True liaison.save() can_take_care = False relations = liaison.liaisondetail_set.filter(qfilter) return object_detail(request, public_liaisons, template_name="liaisons/liaisondetail_detail.html", object_id=object_id, extra_context = {'can_edit': can_edit, 'relations': relations, 'can_take_care': can_take_care} )
def generic_wrapper_detail(request, *args, **kwargs): if request.user.is_anonymous(): queryset = Entry.objects.filter(status='P', pub_date__lte=datetime.datetime.now()) else: queryset = Entry.objects.all() return object_detail(request, queryset, *args, **kwargs)
def blog_view(request, slug_name, author_name): # note - this is currently only used for a specfic blog view and author view - not the front page of the "blogs" section of the site # check urls.py carefully is_owner = False #find the required blog via its slug 'slug_name' if not slug_name is None: blogs = Blog.objects.all().filter(slug=slug_name).order_by('-published_date') author_view = False blog_view = True bauthor = None sticky_blogs = None is_owner = is_owner_of(request, blogs[0]) else: #no slugname - author view bauthor = User.objects.all().filter(username=author_name)[0] blogs = Blog.objects.all().filter(author=bauthor, sticky=False).order_by('-published_date') sticky_blogs = Blog.objects.all().filter(author=bauthor, sticky=True).order_by('-published_date') author_view = True blog_view = False #get list of latest bloggers bloggers = latest_bloggers(Blog.objects.all().order_by('-published_date')) #paginate results blog_paginator = paginate(request,blogs) extra_context = {'bloggers':bloggers, 'blogs':blog_paginator, 'blog_view':blog_view, 'author_view':author_view, 'bauthor':bauthor, 'sticky_blogs':sticky_blogs, 'is_owner':is_owner} template_file_name='blogs' page_name='blogs' # find the page object which represents the actual page (not blogs within page) by its slug name 'page_name' , and the template return object_detail( request, queryset = Page.objects.filter(slug=page_name), slug=page_name, template_name="transitlabourapp/%s.html"%template_file_name, extra_context=extra_context )
def job_confirm(request, job_id, auth): ''' A view to confirm a recently created job, if it has been published by a previously approved user then it gets automatically published, if not then it will need to be verified by a moderator. ''' job = get_object_or_404(Job, pk=job_id, auth=auth) if job.status not in (Job.ACTIVE, Job.TEMPORARY): raise Http404 new_post = job.is_temporary() requires_mod = not job.email_published_before() and \ djobberbase_settings.DJOBBERBASE_ENABLE_NEW_POST_MODERATION if requires_mod: messages.add_message(request, messages.INFO, _('Your job post needs to be verified by a moderator.')) if djobberbase_settings.DJOBBERBASE_POSTER_NOTIFICATIONS: pending_email = MailPublishPendingToUser(job, request) pending_email.start() else: messages.add_message(request, messages.INFO, _('Your job post has been published.')) if not job.is_active(): job.activate() if new_post: if djobberbase_settings.DJOBBERBASE_POSTER_NOTIFICATIONS: publish_email = MailPublishToUser(job, request) publish_email.start() queryset = Job.objects.all() if djobberbase_settings.DJOBBERBASE_ADMIN_NOTIFICATIONS: admin_email = MailPublishToAdmin(job, request) admin_email.start() return object_detail(request, queryset=queryset, object_id=job_id, extra_context={'page_type':'confirm'})
def group_detail(request, slug, **kwargs): return list_detail.object_detail( request, queryset=Group.objects.all(), slug=slug, **kwargs )
def info_page(request, slug='index'): """Show the page, or 'index' if no slug""" return object_detail( request, queryset=InfoPage.objects, slug=slug, )
def entry_detail(request, object_id): return list_detail.object_detail( request, object_id = object_id, queryset = Entry.objects.all(), template_object_name = 'entry' )
def jobrole_detail(request, object_id): return object_detail ( request, queryset = JobRole.objects.all(), object_id = object_id, template_name = 'contact/jobrole_detail.html', )
def joblisting_detail(request, object_id): jobs = gatekeeper.approved(JobListing.objects.filter(pk=object_id)) other_jobs = gatekeeper.approved(JobListing.objects.open().exclude(pk=object_id).order_by("?"))[:5] try: return object_detail(request, queryset=jobs, object_id=object_id, template_object_name="job", extra_context={"other_jobs":other_jobs}) except Http404: return HttpResponse("couldn't find job")
def event_time_detail(request, event_time_id, event_slug, template_name = 'event_time.html'): event_time = get_object_or_404(EventTime, id = event_time_id, event__slug = event_slug) attending = False past = False if event_time.end < datetime.datetime.now(): past = True if request.user.is_authenticated() \ and event_time in [x.event_time for x in request.user.attendee_set.all()] \ or event_time in request.session.get('event_times',[]): attending = True if request.user.is_authenticated(): request.session['name'] = '' return list_detail.object_detail( request, queryset = EventTime.objects.filter(id=event_time_id, event__slug = event_slug), template_name = template_name, object_id = event_time_id, extra_context = {'attending':attending, 'name':request.session.get('name', None), 'past':past}, template_object_name = 'event_time', )
def View_available_goods_detail(request, id): return object_detail(request, queryset=GoodsResource.objects.all(), object_id=id, template_name='ViewAvailableGoods/detail.html', template_object_name='ViewAvailableGoods', context_instance=RequestContext(request))
def topic_detail(request, slug): """ A detail view of a Topic Templates: ``<topic_template_name>`` If the :model:`faq.Topic` object has a ``template_name`` value, the system will attempt to load that template. :template:`faq/topic_detail.html` If there is no ``template_name`` given or the template specified does not exist the standard template will be used. Context: topic An :model:`faq.Topic` object. question_list A list of all published :model:`faq.Question` objects that relate to the given :model:`faq.Topic`. """ extra_context = { 'question_list': Question.objects.published().filter(topic__slug=slug), } return object_detail(request, queryset=Topic.objects.published(), extra_context=extra_context, template_object_name='topic', template_name_field='template_name', slug=slug)
def LocalGovernment_detail(request, id): return object_detail(request, queryset=LocalGovernment.objects.all(), object_id=id, template_name='ManageResources/detail.html', template_object_name='LocalGovernment')
def photo_detail(request, project_id, photo_id): if not request.GET.get('ajax'): return project_overview(request, project_id) photo = Photo.objects.get(id=photo_id) info = get_exif(photo.fullurl()[1:]) if info: dt = info.get('DateTime') or info.get('DateTimeOriginal') or info.get( 'DateTimeDigitized') if dt: dt = datetime.strptime(dt, '%Y:%m:%d %H:%M:%S') else: dt = None else: dt = None # Mode mode = project_getmode_helper(request, project_id) is_view_mode = mode == 'view' return object_detail(request, Photo.objects.all(), object_id=photo_id, template_object_name='photo', template_name='stockphoto/photo_detail.html', extra_context={ 'project_id': project_id, 'datetime': dt, 'is_view_mode': is_view_mode })
def Goods_details(request, id): return object_detail(request, queryset=GoodsResource.objects.all(), object_id=id, template_name='ManageResources/detail_goods.html', template_object_name='GoodsResource')
def liaison_approval_detail(request, object_id): if is_secretariat(request.user): to_approve = LiaisonDetail.objects.filter(approved=None).order_by("-submitted") else: person = get_person_for_user(request.user) approval_codes = IETFHM.get_all_can_approve_codes(person) if settings.USE_DB_REDESIGN_PROXY_CLASSES: to_approve = approvable_liaison_statements(approval_codes).order_by("-submitted") else: to_approve = LiaisonDetail.objects.filter(approval__isnull=False, approval__approved=False, from_raw_code__in=approval_codes).order_by("-submitted_date") if request.method=='POST' and request.POST.get('do_approval', False): try: liaison = to_approve.get(pk=object_id) if settings.USE_DB_REDESIGN_PROXY_CLASSES: liaison.approved = datetime.datetime.now() liaison.save() else: approval = liaison.approval if not approval: approval = OutgoingLiaisonApproval.objects.create(approved=True, approval_date=datetime.datetime.now()) liaison.approval = approval liaison.save() else: approval.approved=True approval.save() liaison.send_by_email() except LiaisonDetail.DoesNotExist: pass return HttpResponseRedirect(reverse('liaison_list')) return object_detail(request, to_approve, object_id=object_id, template_name='liaisons/liaisondetail_approval_detail.html', )
def Rent_details(request, id): return object_detail(request, queryset=RentResource.objects.all(), object_id=id, template_name='ManageResources/detail_rent.html', template_object_name='gymResource')
def view_entry(request, entry_id, account_id=None): if not request.user.is_superuser: entry = get_object_or_404(Entry, owner=request.user, pk=entry_id) else: entry = get_object_or_404(Entry, pk=entry_id) if account_id: account = get_object_or_404(Account, pk=account_id) if entry.account != account: raise Http404 extra_context = { 'account': account, } else: extra_context = {} qs = Entry.objects.filter(pk = entry_id) return object_detail( request = request, queryset = qs, object_id = entry_id, template_name = "entry_detail.html", extra_context = extra_context, )
def phone_detail(request, object_id): return object_detail ( request, queryset = Phone.objects.all(), object_id = object_id, template_name = 'core/phone_detail.html', # FIXME: )
def event_view(request, slug_name, author_name): #find the required blog via its slug 'slug_name' is_owner = False if not slug_name is None: events = Event.objects.all().filter(slug=slug_name).order_by('starting_date') author_view = False event_view = True bauthor = None is_owner = is_owner_of(request,events[0]) else: bauthor = User.objects.all().filter(username=author_name)[0] events = Event.objects.all().filter(author=bauthor).order_by('starting_date') author_view = True event_view = False blogs = Blog.objects.all().order_by('-published_date') bloggers=latest_bloggers(blogs) events_paginator = paginate(request,events) extra_context = {'bloggers':bloggers, 'events':events_paginator, 'event_view':event_view, 'author_view':author_view, 'bauthor':bauthor, 'is_owner':is_owner} template_file_name='events' page_name='events' # find the page object which represents the actual page (not blogs within page) by its slug name 'page_name' , and the template return object_detail( request, queryset = Page.objects.filter(slug=page_name), slug=page_name, template_name="transitlabourapp/%s.html"%template_file_name, extra_context=extra_context )
def im_detail(request, object_id): return object_detail ( request, queryset = IM.objects.all(), object_id = object_id, template_name = 'core/im_detail.html', # FIXME: )
def book_detail(request, book_id): return object_detail( request, queryset = Book.objects.all(), object_id = book_id, template_object_name = 'book', )
def preview(request, code=None, api=False, template_name=None): ## if the page is being accessed as API, return the clean data if api is True: if code is None: url = request.GET.get('url') code = url.rstrip('/').split('/')[-1] object_id = SequenceMapper.to_decimal(code) try: shorturl = ShortURL.objects.get(pk=object_id).url except ShortURL.DoesNotExist: shorturl = '' return _api_response(shorturl, request.GET.get('type')) ## get the object id from code object_id = SequenceMapper.to_decimal(code) template_name = template_name or 'base_shorturl_preview.html' info_dict = { 'queryset': ShortURL.objects, 'object_id': object_id, 'template_name': template_name, } return list_detail.object_detail(request, **info_dict)
def cert_revoke(request, cert_id): # Look up the Cert (and raise a 404 if not found) cert = get_object_or_404(Cert, pk=cert_id) if cert.pubkey.user != request.user: raise Http404 if request.method == "POST": hidden = request.POST.get('post', None) if hidden and hidden == "yes": revoke_cert(cert) #XXX we should use messages here. return render_to_response( 'django_webid/provider/cert_revoked.html', { "MEDIA_URL": settings.MEDIA_URL, "STATIC_URL": settings.STATIC_URL, }) if request.method == "GET": # Show the detail page # with a confirmation message. return list_detail.object_detail( request, queryset=Cert.objects.all(), object_id=cert_id, template_name="django_webid/provider/cert_revoke.html" )
def mailbox_detail(request, slug, **kwargs): return list_detail.object_detail( request, queryset=Mailbox.objects.all(), slug=slug, **kwargs )
def detail(request, proj_id): '''Show information about the project''' project = get_object_or_404(Project, id=proj_id) role_reqs = ProjectRoleRequest.objects.filter( giver=request.user, requested_role__project=project) # Structure with members, ids and roles to pass to project template permittees = project.members_as_permittees.all() member_roles = dict() for permittee in permittees: member_roles[str(permittee.object.username)] = { "id": str(permittee.object.id), "roles": permittee.projectrole_set.filter(project__name=project.name) } return list_detail.object_detail(request, Project.objects.all(), object_id=proj_id, template_name=TEMPLATE_PATH + "/detail.html", template_object_name="project", extra_context={ "role_requests": role_reqs, "member_roles": member_roles, "breadcrumbs": ( ("Home", reverse("home")), ("Project %s" % project.name, reverse("project_detail", args=[project.id])), ) })
def share_detail(request, share_id): """ A shared item, in detail. """ return object_detail(request, SharedItem.objects.select_related(), object_id=share_id, template_object_name='share', template_name='sharing/item.html')
def liaison_detail(request, object_id): if settings.USE_DB_REDESIGN_PROXY_CLASSES: qfilter = Q() public_liaisons = LiaisonDetail.objects.exclude( approved=None).order_by("-submitted_date") else: qfilter = Q(approval__isnull=True) | Q(approval__approved=True) public_liaisons = LiaisonDetail.objects.filter(qfilter).order_by( "-submitted_date") liaison = get_object_or_404(public_liaisons, pk=object_id) can_edit = False user = request.user can_take_care = _can_take_care(liaison, user) if user.is_authenticated() and can_edit_liaison(user, liaison): can_edit = True if request.method == 'POST' and request.POST.get('do_action_taken', None) and can_take_care: liaison.action_taken = True liaison.save() can_take_care = False relations = liaison.liaisondetail_set.filter(qfilter) return object_detail(request, public_liaisons, template_name="liaisons/liaisondetail_detail.html", object_id=object_id, extra_context={ 'can_edit': can_edit, 'relations': relations, 'can_take_care': can_take_care })
def detail(request, id, slug): return object_detail( request, queryset=Event.objects.all(), object_id=id, )
def book_detail(request, book_id): return object_detail( request, queryset=Book.objects.all(), object_id=book_id, template_object_name='book', extra_context={'allow_user_comments': settings.ALLOW_USER_COMMENTS})
def person_detail(request, object_id): return object_detail ( request, queryset = Person.objects.all(), object_id = object_id, template_name = 'contact/person_detail.html', )
def csv_import(request, object_id, **kwargs): if not kwargs.get("template_name"): kwargs["template_name"] = 'csvimporter/csv_import.html' if not kwargs.get("form_class"): kwargs["form_class"] = CSVImportForm kwargs = prepare_view(request, kwargs) instance = get_object_or_404(CSV, pk=object_id) if request.method == 'POST': form = kwargs["form_class"](instance, request.POST) if form.is_valid(): form.save(request) request.user.message_set.create(message=_('CSV imported.')) kwargs["redirect_url"] = reverse('csv_result', args=[instance.id]) return HttpResponseRedirect(kwargs["redirect_url"]) else: messages.info(request, _('Uploaded CSV. Please associate fields below.')) form = CSVImportForm(instance) kwargs["extra_context"].update({"form": form}) return object_detail(request, queryset=CSV.objects.all(), object_id=object_id, template_name=kwargs["template_name"], template_object_name='csv', extra_context=kwargs["extra_context"], )
def project_detail(request, slug): projects = Project.live.all() return object_detail(request, queryset=projects, slug=slug, template_object_name='project', template_name='portfolio/project_detail.html',)
def person_type_detail(request, slug, **kwargs): return list_detail.object_detail( request, queryset = PersonType.objects.all(), slug = slug, **kwargs )
def server_detail(request, object_id): return list_detail.object_detail( request, queryset=Server.objects.all(), template_name='techventory/server_detail.html', object_id=object_id, )
def file_view(request, id): return object_detail( request, queryset=models.File.objects.all(), object_id=id, template_name='filer/view.html', )
def profile(request): """Show a user profile.""" object_id = request.user.userprofile.id queryset = UserProfile.objects.all() return object_detail(request, queryset=queryset, object_id=object_id, template_name='accounts/profile.html', template_object_name='profile')
def place_detail(request, slug, **kwargs): return list_detail.object_detail( request, queryset = Place.objects.all(), slug = slug, **kwargs )
def comic_strip_detail(request, strip_id): return list_detail.object_detail( request, ComicStrip.objects.filter(language=request.LANGUAGE_CODE), id=strip_id, template_object_name='comic_strip', )
def file_view(request, id): return object_detail ( request, queryset = models.File.objects.all(), object_id = id, template_name = 'core/file_view.html', )
def photo_detail(request, project_id, photo_id): if not request.GET.get('ajax'): return project_overview(request, project_id) photo = Photo.objects.get(id=photo_id) info = get_exif(photo.fullurl()[1:]) if info: dt = info.get('DateTime') or info.get('DateTimeOriginal') or info.get('DateTimeDigitized') if dt: dt = datetime.strptime(dt, '%Y:%m:%d %H:%M:%S') else: dt = None else: dt = None # Mode mode = project_getmode_helper(request, project_id) is_view_mode = mode == 'view' return object_detail( request, Photo.objects.all(), object_id=photo_id, template_object_name='photo', template_name='stockphoto/photo_detail.html', extra_context={'project_id': project_id, 'datetime': dt, 'is_view_mode': is_view_mode} )