Esempio n. 1
0
def register_POST(request):
    user = auth.models.User(is_staff=False, is_superuser=False, is_active=True)
    form = accountui.RegistrationForm(request.POST, instance=user)
    if form.is_valid():
        user = form.save()

        salt = sha.new(str(random())).hexdigest()[:5]
        confirmation_key = sha.new(salt + user.username).hexdigest()
        profile = models.UserProfile(user=user, confirmation_key=confirmation_key)
        profile.save()

        email_subject = "Email address confirmation"
        email_body = (
"""Hello %(user)s and thanks for signing up for a traveli.st account!
To confirm your email address click this link:
http://traveli.st/account/confirm-email/?username=%(user)s&key=%(key)s""" % (
                {'user': user.username,
                 'key': profile.confirmation_key}))
        mail.send_mail(email_subject,
                       email_body,
                       settings.SERVER_EMAIL,
                       [user.email])
        return views.render("account_register.html", request, {'created': True})
    else:
        return views.render("account_register.html", request, {'form': form})
Esempio n. 2
0
def confirm_email(request):
    username = request.GET['username']
    key = request.GET['key']
    user_profile = shortcuts.get_object_or_404(models.UserProfile, user__username=username, confirmation_key=key)
    user_profile.email_confirmed = True
    user_profile.save()
    return views.render("account_confirmed_email.html", request)
Esempio n. 3
0
def edit_POST(request, trip):
    form = tripui.EditForm(request.POST, instance=trip)
    if form.is_valid():
        trip = form.save()
        return http.HttpResponseRedirect(trip.get_absolute_url())
    else:
        return views.render("trip_edit.html", request, {'trip': trip, 'form': form})
Esempio n. 4
0
def login_POST(request):
    form = accountui.LoginForm(request.POST)
    if form.is_valid():
        auth.login(request, form.cleaned_data['user'])
        return http.HttpResponseRedirect("/")
    else:
        return views.render("account_login.html", request, {'form': form})
Esempio n. 5
0
def new_POST(request, annotation):
    form = annotationui.EditForm(request.POST, request.FILES, annotation=annotation)
    if form.is_valid():
        form.save()
        return http.HttpResponseRedirect(annotation.trip.get_absolute_url())
    else:
        return views.render("annotation_edit.html", request, {'annotation': annotation, 'form': form})
Esempio n. 6
0
 def render(self, request):
     content = simplejson.loads(self.annotation.content)
     trip = self.annotation.trip
     all_flickr_photos = list(
         trip.get_annotations_visible_to(request.user).filter(content_type=models.ContentType.FLICKR_PHOTO)
     )
     count = len(all_flickr_photos)
     for current in range(count):
         if all_flickr_photos[current] == self.annotation:
             break
     prev = all_flickr_photos[current - 1]
     next = all_flickr_photos[(current + 1) % count]
     current += 1  # make it 1-based
     return views.render(
         "annotation_view_flickr_photo.html",
         request,
         {
             "trip": trip,
             "annotation": self.annotation,
             "photo": content,
             "current": current,
             "count": count,
             "prev": prev,
             "next": next,
         },
     )
Esempio n. 7
0
def profile_POST(request):
    form = accountui.ProfileForm(request.POST, request.FILES, instance=request.user.get_profile())
    if form.is_valid():
        form.save()
        return http.HttpResponseRedirect("/")
    else:
        connect_form = accountui.ProfileConnectForm({'twitter_username': request.user.get_profile().twitter_username})
        return views.render("account_profile.html", request, {'form': form, 'connect_form': connect_form})
Esempio n. 8
0
def edit_POST(request, place):
    form = placeui.EditForm(request.POST, instance=place)
    if form.is_valid():
        form.save()
        hist = models.PlaceHist(place=place, wiki_content=place.wiki_content, user=request.user)
        hist.save()
        return http.HttpResponseRedirect(place.get_absolute_url())
    else:
        return views.render("place_edit.html", request, {"place": place, "form": form})
Esempio n. 9
0
def view(request, id):
    place = shortcuts.get_object_or_404(models.Place, id=id)

    if request.user.is_anonymous():
        user_ratings = []
    else:
        user_ratings = models.PlaceRating.objects.filter(place=place, user=request.user)
    user_rating = user_ratings[0] if len(user_ratings) == 1 else None

    return views.render("place.html", request, {"place": place, "user_rating": user_rating})
Esempio n. 10
0
def view(request, id):
    accommodation = shortcuts.get_object_or_404(models.Accommodation, id=id)

    if request.user.is_anonymous():
        user_ratings = []
    else:
        user_ratings = models.AccommodationRating.objects.filter(accommodation=accommodation, user=request.user)
    user_rating = user_ratings[0] if len(user_ratings) == 1 else None

    return views.render("accommodation.html", request, {'accommodation': accommodation, 'user_rating': user_rating})
Esempio n. 11
0
def edit_POST(request, accommodation):
    form = accommodationui.EditForm(request.POST, instance=accommodation)
    if form.is_valid():
        form.save()
        hist = models.AccommodationHist(accommodation=accommodation,
                                        wiki_content=accommodation.wiki_content,
                                        user=request.user)
        hist.save()
        return http.HttpResponseRedirect(accommodation.get_absolute_url())
    else:
        return views.render("accommodation_edit.html", request, {'accommodation': accommodation, 'form': form})
Esempio n. 12
0
def edit_POST(request, annotation):
    form = annotationui.EditForm(request.POST, request.FILES, annotation=annotation)
    if form.is_valid():
        form.save()
        if request.is_ajax():
            return http.HttpResponse(serialize('json', [annotation]))
        else:
            return http.HttpResponseRedirect(annotation.trip.get_absolute_url())
    else:
        if request.is_ajax():
            return http.HttpResponseBadRequest()
        else:
            return views.render("annotation_edit.html", request, {'annotation': annotation, 'form': form})
Esempio n. 13
0
def details(request, id):
    trip = shortcuts.get_object_or_404(models.Trip, id=id)
    if not trip.is_visible_to(request.user):
        raise http.Http404()

    points = dict([(p.id, p) for p in trip.point_set.all()])
    for p in points.values():
        p.annotations = {'POINT': {}, 'SEGMENT': {}}

    annotations = list(trip.get_annotations_visible_to(request.user).all())
    for annotation in annotations:
        if not annotation.point_id:
            continue
        dest = points[annotation.point_id].annotations['SEGMENT' if annotation.segment else 'POINT']
        content_type_name = models.ContentType.get_name(annotation.content_type)
        if not dest.has_key(content_type_name):
            dest[content_type_name] = []
        dest[content_type_name].append(annotation)

    points = sorted(points.values(), key=lambda p: p.order_rank)

    segments = []
    for i in range(len(points) - 1):
        p1, p2 = points[i], points[i + 1]
        place_ids = '%s-%s' % (min(p1.place_id, p2.place_id), max(p1.place_id, p2.place_id))
        segments.append({'place_ids': place_ids, 'p1': p1, 'p2': p2, 'length': distance(p1.coords, p2.coords).km})

    trip_notes = [a for a in annotations if a.content_type in [models.ContentType.NOTE, models.ContentType.TWEET]]
    trip_photos = [a for a in annotations if a.content_type in [models.ContentType.EXTERNAL_PHOTOS, models.ContentType.FLICKR_PHOTO]]
    trip_links = [(l.lhs if l.rhs == trip else l.rhs, l)
                  for l in models.TripLink.objects.filter(Q(lhs=trip) | Q(rhs=trip), status=models.RelationshipStatus.CONFIRMED)]
    trip_links = [l for l in trip_links if l[0].is_visible_to(request.user)]

    return views.render("trip_details.html", request, {'trip': trip, 'points': points, 'segments': segments,
                                                       'points_sorted': sorted(points, key=lambda p: p.place_id), # XXX: needed until #11008 is fixed in Django
                                                       'segments_sorted': sorted(segments, key=lambda s: s['place_ids']), # XXX: needed until #11008 is fixed in Django
                                                       'trip_notes': trip_notes, 'show_trip_notes': trip.user == request.user or trip_notes,
                                                       'trip_photos': trip_photos, 'show_trip_photos': trip.user == request.user or trip_photos,
                                                       'trip_links': trip_links, 'show_trip_links': trip.user == request.user or trip_links})
Esempio n. 14
0
def user(request, username):
    for_user = models.User.objects.get(username=username)
    trips = models.Trip.objects.for_user(owner=for_user, viewer=request.user)
    return views.render("trip_list.html", request, {'trips': trips, 'is_self': for_user == request.user,
                                                    'for_user': for_user})
Esempio n. 15
0
def points_GET(request, id):
    trip = shortcuts.get_object_or_404(models.Trip, id=id, user=request.user)
    points = list(trip.point_set.all())
    widget = forms.widgets.Select(choices=annotationtypes.Transportation.Means.choices)
    return views.render("trip_points.html", request, {'trip': trip, 'points': points,
                                                      'transportation_select': widget.render('default_transportation', None, {'id': 'default_transportation'})})
Esempio n. 16
0
def edit_GET(request, accommodation):
    form = accommodationui.EditForm(instance=accommodation)
    return views.render("accommodation_edit.html", request, {'accommodation': accommodation, 'form': form})
Esempio n. 17
0
def edit_GET(request, trip):
    form = tripui.EditForm(instance=trip)
    return views.render("trip_edit.html", request, {'trip': trip, 'form': form})
Esempio n. 18
0
def edit_GET(request, place):
    form = placeui.EditForm(instance=place)
    return views.render("place_edit.html", request, {"place": place, "form": form})
Esempio n. 19
0
def login_GET(request):
    return views.render("account_login.html", request, {'form': accountui.LoginForm()})
Esempio n. 20
0
def stats(request, username):
    user = models.User.objects.get(username=username)
    trips = list(user.trip_set.all())
    points = list(models.Point.objects.filter(trip__user=user).select_related('trip').select_related('place').select_related('place__country'))
    transportations = dict((t.point_id, int(t.content)) for t in models.Annotation.objects.filter(trip__user=user, content_type=models.ContentType.TRANSPORTATION))

    stats = {None: {}}

    def add_stat(year, stat, value, init):
        if not isinstance(year, int) and year is not None:
            for year in year:
                add_stat(year, stat, value, init)
        else:
            if not year in stats:
                stats[year] = {}
            if not stat in stats[year]:
                stats[year][stat] = init
            if isinstance(init, list):
                stats[year][stat].append(value)
            elif isinstance(init, set):
                stats[year][stat].add(value)
            else:
                stats[year][stat] += value

    for trip in trips:
        add_stat(range(trip.start_date.year, trip.end_date.year + 1), 'trip_count', 1, 0)
	add_stat(None, 'trip_count', 1, 0)

    extreme_N, extreme_S, extreme_E, extreme_W = None, None, None, None
    for point in points:
        if point.visited:
            year_arrived = point.date_arrived.date().year if point.date_arrived else point.trip.start_date.year
            add_stat(year_arrived, 'places', point.place, set())
	    add_stat(None, 'places', point.place, set())
            add_stat(year_arrived, 'countries', point.place.country, set())
	    add_stat(None, 'countries', point.place.country, set())
            if extreme_N is None or point.coords.coords[0] > extreme_N.coords.coords[0]:
                extreme_N = point.place
            if extreme_S is None or point.coords.coords[0] < extreme_S.coords.coords[0]:
                extreme_S = point.place
            if extreme_E is None or point.coords.coords[1] > extreme_E.coords.coords[1]:
                extreme_E = point.place
            if extreme_W is None or point.coords.coords[1] < extreme_W.coords.coords[1]:
                extreme_W = point.place
        next_point = utils.find(points, lambda p: p.trip_id == point.trip_id and p.order_rank > point.order_rank)
        if next_point:
            dist = distance(point.coords, next_point.coords).km
            year_left = point.date_left.date().year if point.date_left else point.trip.start_date.year
            transportation = annotationtypes.Transportation.Means.get_name(transportations[point.id])
            add_stat(year_left, 'distance', dist, 0)
	    add_stat(None, 'distance', dist, 0)
            add_stat(year_left, 'distance_' + transportation, dist, 0)
	    add_stat(None, 'distance_' + transportation, dist, 0)

    for year_stats in stats.values():
        year_stats['places'] = sorted(year_stats.get('places', []))
        year_stats['countries'] = sorted(year_stats.get('countries', []))

    stats[None]['extreme_places'] = {'N': extreme_N, 'S': extreme_S, 'E': extreme_E, 'W': extreme_W}

    return views.render("user_stats.html", request, {'for_user': user,
                                                     'years': [None] + list(sorted(set(stats.keys()) - set([None]), reverse=True)),
                                                     'stats': stats.items()})
Esempio n. 21
0
def map(request, username):
    user = models.User.objects.get(username=username)
    places = list(models.Place.objects.filter(point__trip__user=user, point__visited=True).annotate(visit_count=Count('point')).annotate(rating=Avg('placerating__value')))
    for place in places:
        place.rating = int(place.rating) if place.rating else models.Rating.AVERAGE
    return views.render("user_map.html", request, {'for_user': user, 'places': places})
Esempio n. 22
0
def friends(request, username):
    return views.render("user_friends.html", request, {'for_user': models.User.objects.get(username=username)})
Esempio n. 23
0
def profile(request, username):
    profile = models.UserProfile.objects.filter(user__username=username).select_related('user').get()
    for_user = profile.user
    is_self, is_friend, is_friend_pending = for_user.get_relationship_status(request.user)
    return views.render("user_profile.html", request, {'for_user': for_user, 'is_self': is_self,
                                                       'is_friend': is_friend, 'is_friend_pending': is_friend_pending})
Esempio n. 24
0
def journal(request, id):
    trip = shortcuts.get_object_or_404(models.Trip, id=id)

    return views.render("trip_journal.html", request, {'trip': trip})
Esempio n. 25
0
def view(request, id):
    trip = shortcuts.get_object_or_404(models.Trip, id=id)
    if not trip.is_visible_to(request.user):
        raise http.Http404()
    return views.render("trip.html", request, {'trip': trip})
Esempio n. 26
0
def profile_GET(request):
    profile = request.user.get_profile()
    form = accountui.ProfileForm(instance=profile)
    connect_form = accountui.ProfileConnectForm({'twitter_username': profile.twitter_username,
                                                 'flickr_userid': profile.flickr_userid})
    return views.render("account_profile.html", request, {'form': form, 'connect_form': connect_form})
Esempio n. 27
0
def register_GET(request):
    form = accountui.RegistrationForm()
    return views.render("account_register.html", request, {'form': form})
Esempio n. 28
0
def edit_GET(request, annotation):
    form = annotationui.EditForm(annotation=annotation)
    return views.render("annotation_edit.html", request, {'annotation': annotation, 'form': form})
Esempio n. 29
0
def all(request):
    notifications = models.Notification.objects.filter(user=request.user)
    return views.render("notification_list.html", request, {'notifications': notifications})
Esempio n. 30
0
def view(request, section):
    if section not in available_sections:
        return http.HttpResponseNotFound()
    return views.render("help_%s.html" % section, request)