コード例 #1
0
ファイル: views.py プロジェクト: rheide/Rankkeeper
def addExternalRating(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse("auth_login"))
    else:
        url = request.POST['media_url']
        
        if 'seen_date' in request.POST:
            seenDate = request.POST['seen_date']
        else:
            seenDate = mediamanager.nowDateString()
            
        rating = int(request.POST['media_rating'])
        
        print "Loading from url: "+url
        
        c = Context()
        
        # do stuff here
        sourceMedia = None
        try:
            sourceMedia = mediamanager.addSourceMedia(url)
        except UnknownSourceError, e:
            # Can't help it, really 
            c['ml_error'] = e.value
            return renderPage(request, "ml/addrating_result.html", c)
        except WebLoadError, e:  # Couldn't parse the url
            c['ml_error'] = e.value
            # Store error
            mn = MediaNotification(message="URL add failure",url=url, 
                                   date=mediamanager.nowDateTimeString(),
                                   host=str(request.META['REMOTE_ADDR']),
                                   user=request.user,info="Error: "+e.value)
            mn.save()
            return renderPage(request, "ml/addrating_result.html", c)
コード例 #2
0
ファイル: imdbloader.py プロジェクト: rheide/Rankkeeper
 def __importRating(self, user, key, rating, status, date):
     # Import ratings to database, check if previous ratings exists
     # and maintain a proper event history of everything
     
     # First, resolve the media
     url = self.getUrl(key)
     self.last_url = url #for debug
     try:
         sourceMedia = mediamanager.addSourceMedia(url)
     except MediaTypeNotSupportedError:
         #print "Unsupported media type for url: "+url
         return # Nothing to do yet
     
     #print "Source media " + key + " - " + sourceMedia.media.name
     
     # Then find existing ratings for our media type
     # (IMDB only supports the simple kind of rating)
     ratings = RatingEvent.objects.filter(user=user, 
                                          source=sourceMedia.source,
                                          media=sourceMedia.media,
                                          complex=False).order_by('-date','-id')
     
     addNewRating = True
     if len(ratings) > 0 and ratings[0].rating == rating:
         addNewRating = False # don't add new rating if previous rating already exists
     
     # Special rules for imdb: we ignore statuses (since IMDb doesn't have them)
     # and we only check if the rating changed. duration is ignored completely
     if addNewRating:
         re = RatingEvent()
         re.user = user
         re.media = sourceMedia.media
         re.source = sourceMedia.source
         re.rating = rating
         re.date = mediamanager.nowDateString()
         re.complex = False
         # Always use 'watched' for the status, as IMDB does not offer any choice
         re.status = Status.objects.get(type=sourceMedia.media.type, name="Watched")
         re.save()
         # Get mediamanager to update duration:
         mediamanager.updateStatus(re, re.status.id)