コード例 #1
0
ファイル: views.py プロジェクト: exp-repos/GeoPort
def group_settings(request, slug):
    context = {}
    try:
        group = Group.objects.get(slug=slug)
    except:
        raise Http404
    if request.user not in group.staff:
        raise PermissionDenied

    context['group'] = group
    if request.method == 'POST':
        form = GroupForm(request.POST, request.FILES, instance=group)
        if form.is_valid():
            group = form.save(commit=False)
            group.creator = request.user
            group.tags = form.cleaned_data['tags']
            if form.cleaned_data['logo']:
                path = handle_uploaded_file(request.FILES['logo'], 'uploads')
                old_path = group.logo
                if old_path:
                    delete_file(old_path)
                group.logo = path
            group.save()
            return HttpResponseRedirect(group.get_absolute_url())
        else:
            # Retain POST data if invalid
            data = get_post_data(request, *form.fields)
            form.initial = data
            #context['form'] = form
    else:
        form = GroupForm(instance=group)
        form.initial = get_initial_data(group, *form.fields)
        form.initial['tags'] = ','.join(form.initial['tags'])
    context['form'] = form
    return render(request, 'groups/group_settings.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: exp-repos/GeoPort
def edit(request, group_slug, event_id):
    try:
        group = Group.objects.get(slug=group_slug)
    except:
        raise Http404
    try:
        event = Event.objects.get(group=group, id=event_id)
    except:
        raise Http404
    if request.user not in group.staff:
        return PermissionDenied
    context = {}
    context['group'] = group
    context['event'] = event
    if request.method == 'POST':
        form = EventForm(request.POST, request.FILES, instance=event)
        #d = get_post_data(request, *form.fields)
        #print d
        if form.is_valid():
            event = form.save(commit=False)
            event.creator = request.user
            event.group = group
            event.tags = form.cleaned_data['tags']
            event.location = form.cleaned_data['location']
            event.save()
            return HttpResponseRedirect(event.get_absolute_url())
        else:
            # Retain POST data if invalid
            data = get_post_data(request, *form.fields)
            form.initial = data
    else:
        form = EventForm(instance=event)
        form.initial = get_initial_data(event, *form.fields)
        form.initial['tags'] = ','.join(form.initial['tags'])
    context['form'] = form
    return render(request, 'events/edit.html', context)