예제 #1
0
파일: forms.py 프로젝트: KCherkasov/mbou
 def save(self):
   data = self.cleaned_data
   gallery = Gallery()
   gallery.title = data.get('title')
   gallery.slug = re.sub(' +', '_', gallery.title)
   gallery.description = data.get('description')
   gallery.save()
   return gallery
예제 #2
0
def create(request):
    if request.method == 'POST' and 'initial' not in request.POST:
        explorer_form = RegistrationForm(request.POST)
        if explorer_form.is_valid():
            # The person correctly filled out the form. Register them
            explorer_form.save(commit=False)
            explorer_form.instance.set_password(explorer_form.cleaned_data['password1'])
            explorer = explorer_form.save()
            explorer = authenticate(
                username=explorer_form.cleaned_data['email'],
                password=explorer_form.cleaned_data['password1']
            )
            # Log new explorer in
            login(request, explorer)
            first_experience = None
            if request.POST.get('title'):
                # Save their experience
                first_experience = ExperienceForm(request.POST,
                        author=explorer).save()
                explorer.featured_experience = first_experience
                explorer.save()
            # Create a gallery for the new explorer
            gallery = Gallery(title=explorer.get_full_name(), title_slug=slugify(explorer.trailname), content_type=ContentType.objects.get_for_model(get_user_model()), object_pk=explorer.id)
            gallery.save()
            gallery.explorers.add(explorer)
            explorer.gallery = gallery
            explorer.save()
            # Welcome and send them on introductory tour
            messages.success(request, 'Welcome aboard, {0}!'.format(explorer.get_full_name()))
            notify.send(sender=explorer, recipient=get_user_model().objects.get(pk=1), verb='is now a fellow explorer')
            if first_experience:
                messages.success(request, '''You can get started by developing
                your experience a little and then making it public when ready, sharing it
                with others and feeling the power you can draw from support 
                along this journey.''')
                return redirect(reverse('experience', args=(first_experience.id,)))
            else:
                return redirect(reverse('journey', args=(explorer.id,)))
    else:
        explorer_form = RegistrationForm()
    return render(request, 'registration/register.html', {
            'form': explorer_form,
            'experience': request.POST.get('title'),
            'min_password_len': settings.MIN_PASSWORD_LEN,
        }
    )
예제 #3
0
def insertIntoGallery(gallery_title,
                      gallery_slug,
                      screenshot,
                      title,
                      slug,
                      gallery_description="",
                      gallery_tags="",
                      caption="",
                      tags="",
                      fab_dir='%s/.fabric-bolt' % (os.path.expanduser('~/'))):
    # Add custom fabric-bolt settings directory
    sys.path.insert(0, fab_dir)
    # Utilize django within fabfile
    # Load custom fabric-bolt settings file
    django.settings_module('settings')
    # Loads the django Models
    get_wsgi_application()
    # Once loaded we can reference them
    from photologue.models import Photo
    from photologue.models import Gallery

    file = open(screenshot, 'rb')
    data = file.read()

    # First Generate or Retrieve the Photo Model and save or update it
    try:
        photo = Photo.objects.get(slug=slug)
        photo.date_added = datetime.now()
        photo.date_taken = datetime.now()
        print("~~~ FOUND existing Screenshot ~~~")
    except Photo.DoesNotExist:
        photo = Photo(
            title=title,
            slug=slug,
            caption=caption,
            is_public=True,
            tags=tags,
        )
        print("~~~ CREATED new Screenshot ~~~")

    try:
        photo.image.save(os.path.basename(screenshot), ContentFile(data))
    except FieldError:
        # For some reason a field, 'photo,' is being passed to model as a field.
        pass
    print("~~~ SAVED Screenshot ~~~")

    # Now Create or Retrieve the named Gallery and add the photo to it.
    gallery = None
    try:
        gallery = Gallery.objects.get(title=gallery_title)
        print("~~~ FOUND existing Screenshot Gallery ~~~")
    except Gallery.DoesNotExist:
        gallery = Gallery(
            title=gallery_title,
            slug=gallery_slug,
            description=gallery_description,
            is_public=True,
            tags=gallery_tags,
        )
        gallery.save()
        print("~~~ CREATED new Screenshot Gallery ~~~")

    if gallery:
        gallery.photos.add(photo)
        print("~~~ Added Screenshot to Gallery ~~~")
        print(
            "<a target=\"_parent\" href=\"/photologue/gallery/%s\">View Screenshot Gallery %s</a>"
        ) % (gallery_title, gallery_title)

    # Reset the syspath
    sys.path.remove(fab_dir)